javi
FFI Difference between buffer and pointer
I’ve been using interchangeably
Deno.UnsafePointer.of(new Uint8Array())
with type pointer
and new Uint8Array()
with type buffer. Is there any major difference? Per se I don’t use char[]
arrays, just pointers.5 replies
Update value by reference without duplicating the data
Im exploring the world of FFI, porting some C applications I have to TypeScript, with the help of Deno. Currently, I cannot think of an efficient way to update the value that a pointer is pointing to. For instance, in C I could do something like:
Nonetheless, with Deno I have to first either allocate memory with an allocator or create a TypedArray myself, then create a new unsafe pointer of that. To update it, I’d have to create an unsafe pointer view of that pointer, get the array buffer, create a
new Uint8Array
from that array buffer, use the <Uint8Array>.set
function to update the chunk of memory, and then create a new unsafe pointer of that, duplicating the memory and adding extra complexity.
Is there another way to do it? Thanks!4 replies