MemoryHeap::CreateArena

MemoryHeap::CreateArena
virtual void CreateArena(UPInt arena, SysAllocPaged* sysAlloc) = 0;
Description

CreateArena creates a memory arena that can be used by the heap for allocation purposes. Please note the following before creating the memory arenas: 

1. The SysAllocPaged objects must remain alive at all times while the arenas are used. 

2. The arenas can be created/destroyed only after the GFx::System object is created. For example, in function main(), the SysAllocPageds must be created before GFx::System to ensure they are destroyed only after GFx::System is destroyed. The arenas must be created and destroyed while the GFx::System object is alive.

   MySysAlloc1 alloc1;         // The allocators must remain alive till DestroyArena()
   MySysAlloc2 alloc2;
   GFx::System gfxInit;
   {
       // Create:
       Memory::CreateArena(1, &alloc1); // Or MemoryHeap::CreateArena
       Memory::CreateArena(2, &alloc2); // Or MemoryHeap::CreateArena

       // Use:
       MemoryHeap::Desc desc;

       Desc.Arena = 1; // Heaps will use arena 1
       MemoryHeap* h11 = Memory::pGlobalHeap->CreateHeap("heap11",  desc);
       MemoryHeap* h12 = Memory::pGlobalHeap->CreateHeap("heap12",  desc);

       Desc.Arena = 2; // Heaps will use arena 2
       MemoryHeap* h21 = Memory::pGlobalHeap->CreateHeap("heap21",  desc);
       MemoryHeap* h22 = Memory::pGlobalHeap->CreateHeap("heap22",  desc);

       . . .

       // Check if empty
       if (!Memory::ArenaIsEmpty(1))
       {
            . . .report something terrible
       }

       // Destroy:
       Memory::DestroyArena(1); // Will throw a break if not empty. In Release it will crash at "return *(int*)0;"
       Memory::DestroyArena(2);

       // Now the arenas can be re-created again

       . . .
   }
Parameters
Parameters 
Description 
UPInt arena 
Integer Id of the memory arena used for the heap (e.g., 1, 2 etc) 
SysAllocPaged* sysAlloc 
Pointer to SysAllocPaged implementation for allocating block of memory used as memory arena for the heap.