-
Notifications
You must be signed in to change notification settings - Fork 8
Memory
Memory allocation is platform specific, as such the heap types are defined in each platforms mem_ps.h. All platforms must define MEMTYPE_STANDARD and MEMTYPE_NETWORK in their MemType enums, but they are free to add additional heaps for platform specific allocations.
All memory in Usagi is tracked to easily detect memory leaks.
The list of allocation types can be found in Allocator.h (you can append to this list but if you do be sure to add to gszAllocStrings in mem.cpp. This should be refactored).
Do NOT use malloc or free, use the usagi functions in the mem namspace Alloc and Free
void* Alloc(MemType eHeap, MemAllocType eType, size_t uSize, uint32 uAlign);
void Free(MemType eHeap, void* pData);
eHeap is either MEMHEAP_STANDARD, MEMHEAP_NETWORK or one of the specified heaps. eType should be one of the values from the MemAllocType enum in Allocator.h and is used for debugging purposes only (when a memory leak occurs that type will be used to try and track it down so you should try and limit the number of allocations using a single type). uSize and uAlign are hopefully self explanatory.
Rather than new you should use the Usagi specific vnew passing in an allocation type.
GameView* pView = vnew(usg::ALLOC_OBJECT)GameView()
vnewHeap allows you to specify the heap to allocate the object from and vnew_aligned allows additionally allows you to specify the alignment.
Memory is tagged as it is allocated so that we can potentially free entire groups, but also to separate memory leaks from data which shouldn't have been freed yet.