reorganize the code into a thread-safe API
fix `reallocate_inplace` with small allocations
add infrastructure for releasing the memory
split out some modules