-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass a void pointer to be allocated in a C function #34
Comments
I will see it later |
try with this code const i32Ptr = createPointer({
paramsType: [DataType.I32Array],
paramsValue: [[-1, -1, -1]]
})[0]
const v = load({
library: "libsum",
funcName: 'alloc_pointer',
retType: DataType.I32,
paramsType: [DataType.External],
paramsValue: [i32Ptr]
});
const unwrapPtr = restorePointer({
paramsValue: [i32Ptr],
retType: [arrayConstructor({
type: DataType.I32Array,
length: 3
})],
})
console.log('111', unwrapPtr) |
It worked! But do I need to know the size of the array that was allocated to use restorePointer and to create the pointer? I will need to work with Buffer and won't know what size it will be allocated. |
There's no good way if you don't know the length of array, because restore array data by offset pointer is unsafe, we must guarantee the address to which the pointer point is valid. I will also think whether there has other way to implement this feature |
An interim solution is create a big and fixed length space to store the return data |
I really appreciate the help. |
I'm trying to use a function in C to pass a pointer, have it allocated and modified in C, and then retrieve this modified pointer in Node.js. However, I'm unable to do it at all. Can you help me?
C function:
Node example:
The text was updated successfully, but these errors were encountered: