3 ms·
The common use case for doing that in other FFIs is not to use it in your own language, but to pass the pointer to another function. That is, you can translate
by geofft 10y ago
The common use case for doing that in other FFIs is not to use it in your own language, but to pass the pointer to another function. That is, you can translate
int *buffer = malloc(10);
SSL_read(ssl, buffer, 10);
into
let buffer = ffi('void *malloc(int)');
let SSL_read = ffi('int SSL_read(void *ssl, void *buf, int num)');
let buffer = malloc(10);
SSL_read(ssl, buffer, 10);
Your own language generally has ways to allocate memory—but does not necessarily have a way to generate a pointer, or to manually manage the lifetime of that memory.