/** * Initialise an expanded heap. * * Adds it to the list of active heaps. */ ExpandedHeap * MEMCreateExpHeapEx(ExpandedHeap *heap, uint32_t size, uint16_t flags) { // Setup state auto base = mem::untranslate(heap); heap->size = size; heap->bottom = base; heap->top = base + size; heap->mode = MEMExpHeapMode::FirstFree; heap->group = 0; heap->usedBlockList = nullptr; heap->freeBlockList = make_virtual_ptr<ExpandedHeapBlock>(base + sizeof(ExpandedHeap)); heap->freeBlockList->addr = heap->freeBlockList.getAddress(); heap->freeBlockList->size = heap->size - sizeof(ExpandedHeap); heap->freeBlockList->next = nullptr; heap->freeBlockList->prev = nullptr; // Setup common header MEMiInitHeapHead(heap, MEMiHeapTag::ExpandedHeap, heap->freeBlockList->addr, heap->freeBlockList->addr + heap->freeBlockList->size); return heap; }
ExpandedHeap * MEMCreateExpHeapEx(ExpandedHeap *heap, uint32_t size, uint16_t flags) { // Allocate memory auto base = gMemory.untranslate(heap); gMemory.alloc(base, size); // Setup state heap->size = size; heap->bottom = base; heap->top = base + size; heap->mode = HeapMode::FirstFree; heap->group = 0; heap->usedBlockList = nullptr; heap->freeBlockList = make_p32<ExpandedHeapBlock>(base + sizeof(ExpandedHeap)); heap->freeBlockList->addr = static_cast<uint32_t>(heap->freeBlockList); heap->freeBlockList->size = heap->size - sizeof(ExpandedHeap); heap->freeBlockList->next = nullptr; heap->freeBlockList->prev = nullptr; // Setup common header MEMiInitHeapHead(heap, HeapType::ExpandedHeap, heap->freeBlockList->addr, heap->freeBlockList->addr + heap->freeBlockList->size); return heap; }