DLL Boundary Safe Memory ManagementΒΆ

Passing pointers across DLL boundaries could lead to heap corruption if the DLLs use different runtimes. Each runtime has its own heap manager, so attempting to free memory in a DLL that was allocated in a different DLL is unsafe (source). However it is desirable to be able to pass pointers, or objects that contain pointers (such as a string), across DLL boundaries. In order to achieve this, Carbonite provides memory management functions that are DLL boundary safe.

There are three available functions: carb::allocate(), carb::deallocate(), and carb::reallocate(). These functions are analagous to malloc, free, and realloc. These functions all use a memory management function in carb.dll, so that all allocations and deallocations use the same C Runtime, and thus are safe for use by different plugins.