0

我在本机 C 库中有一个函数,它具有以下标头,我从节点调用:

int DLLAPI fill(char* file, double*** dataBuf)

参数是一个缓冲区,dataBuf将由函数填充一个二维数组,大小为 X (10) x Y (10000)。我也能够在节点端获得这些长度。(因为它们因文件而异)

我正在使用node-ffiref模块来调用该函数。简而言之,这就是我已经拥有的:

// Initialize the node-ffi library
var TheLibrary = ffi.Library(path.join(binDirectory, "NativeLibrary"), {
    "fill": ["int", ["string", "pointer"]]
});

var length_X = 10; // variable, placeholder
var length_Y = 10000; // variable, placeholder

// Argument buffers
var buf_data = ref.ref(ref.ref(ref.alloc('double'))); // double***
// Note: the buffer is empty at first (no need to allocate the memory), the DLL function does that.

// Calling the function
var status = TheLibrary.fill(this.file, buf_data);

// Reading the data
var deref_data = ref.deref(buf_data);
// deref_data[length_X - 1][length_Y - 1]? How should I read the array here

我尝试使用 ref-array 库做一些事情,它对一维数组非常有效,但我从来没有让它与二维数组一起使用,因为它假设因为数组长度(元素)是静态的,所以必须是以字节为单位的数组。(不适用于二维数组)

我应该如何从节点中的指针读取二维数组?

4

0 回答 0