我想将大量对象malloc到内存中。(大约1亿个对象)因为golang的gc不够有效,所以我需要使用c/c++来malloc内存并使用std::vector来保存对象。这是我的代码,我想在 cgo 中使用 std 容器:
package main
import (
"fmt"
)
/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
void dosome(){
vector<int> ivec; // empty vector
for (vector<int>::size_type ix = 0; ix != 10; ++ix)
ivec[ix] = ix; // disaster: ivec has no elements
}
*/
// #cgo LDFLAGS: -lstdc++
import "C"
//import "fmt"
func main() {
C.dosome()
var input string
fmt.Scanln(&input)
}
并在下面显示错误消息:
go run stddemo.go
# command-line-arguments
./stddemo.go:13:10: fatal error: 'vector' file not found
#include <vector>
^
1 error generated.
我该如何设置包含路径或者还有其他想法吗?