TooTallNate / ref

Turn Buffer instances into "pointers"
http://tootallnate.github.com/ref
451 stars 141 forks source link

How to access C++ Dynamic Memory Allocation #94

Closed helvenk closed 6 years ago

helvenk commented 6 years ago

I think the codes below is clear

// example.cpp
function alloc(int **p) {
    return *p = new int[10];
}

// example.js
var ptrPtr = ref.alloc(ref.refType(ref.types.int));

// pass the `ptrPtr ` to function `alloc`, use `node-ffi`
// ...

// now, `ptrPtr.deref()` should point to an array, but it points to `*p[0]`, 
// how to access `*p[1]`, `*p[2]`, ... ?
console.log(ptrPtr.deref());
helvenk commented 6 years ago

@TooTallNate I need your help