Memory allocator is a simple CandidType struct. More info on how functions like stable_memory_init() or stable_memory_post_upgrade()
affect the memory allocator can be found at this page.
Here is a diagram that describes the complete memory management flow.
