2 ms·
Yeah I don’t know how a C library without `_free()` calls would work across FFI (like making bindings).
by avgcorrection 3y ago
Yeah I don’t know how a C library without `_free()` calls would work across FFI (like making bindings).
- the-smug-one 3y agoWhy would FFI be an issue?
- avgcorrection 3y agoMaybe you allocate a string and pass it to Rust code. Then the Rust code needs a way to free it (through `drop`).
- dwattttt 3y ago1st approach) you don't 2nd approach for when you ignore the first) you use a type that doesn't "own" the pointer, and have the FFI side that allocated it free it 3rd approach for when you find out you can't do the 2nd) hope that the "owned" type is actually generic over the allocator used, and make an allocator that doesn't free (or even better, calls the correct free over the FFI boundary). `allocator-api` is the effort in this direction.
- steveklabnik 3y agoIt’s important to use the same allocator to free as you allocate with. You can’t assume that the same allocator is linked to both sides, so if you are allocating and then giving something to something else over FFI, you want to make sure you give them a way to call back into you to free. This is true irrespective of language.