golang 学习记录
生活随笔
收集整理的這篇文章主要介紹了
golang 学习记录
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
package main/*
?? ?#include <stdio.h>
?? ?#include <stdlib.h>
?? ?struct CType {
?? ??? ?int Id;
?? ??? ?int Id2;
?? ?};
?? ?typedef struct CType TheCType;
?? ?TheCType *getTheArray(int length){
?? ??? ?TheCType *ctype;
?? ??? ?ctype = malloc(length*sizeof(TheCType));
?? ??? ?return ctype;
?? ?}
?? ?void Free(TheCType *ctype){
?? ??? ?free(ctype);
?? ?}
*/
import "C"
import (
?? ?//"fmt"
?? ?"reflect"
?? ?//"time"
?? ?"unsafe"
)
var theGoSlice []C.TheCType
func cc() {
?? ?length := C.int(500000)
?? ?var theCArray = C.getTheArray(length)
?? ?C.Free(theCArray)
?? ?sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&theGoSlice)))
?? ?sliceHeader.Cap = int(uintptr(length))
?? ?sliceHeader.Len = int(uintptr(length))
?? ?sliceHeader.Data = uintptr(unsafe.Pointer(theCArray))
}
不知道是否正確
轉載于:https://my.oschina.net/u/1408729/blog/178403
總結
以上是生活随笔為你收集整理的golang 学习记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线上lnmp环境快速安装
- 下一篇: R12 - OM改进了对成本与收入确认的