/*---------------------------------------------------------------------------* Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* Project: MEM library File: unitHeap.h Programmers: Takano Makoto Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #ifndef MEM_UNITHEAP_H__ #define MEM_UNITHEAP_H__ #ifdef __cplusplus extern "C" { #endif #include #include /* ======================================================================== Type Definitions ======================================================================== */ typedef struct MEMiUntHeapMBlockHead MEMiUntHeapMBlockHead; // Header information for the memory block. struct MEMiUntHeapMBlockHead { MEMiUntHeapMBlockHead* pMBlkHdNext; // Next block. }; typedef struct MEMiUntMBlockList MEMiUntMBlockList; // Memory block list. struct MEMiUntMBlockList { MEMiUntHeapMBlockHead* head; // Pointer to the memory block linked to the header. }; typedef struct MEMiUntHeapHead MEMiUntHeapHead; // Header information for the unit heap. struct MEMiUntHeapHead { MEMiUntMBlockList mbFreeList; // Free list. u32 mBlkSize; // Memory block size. }; /* ======================================================================== Macro Functions ======================================================================== */ /* ======================================================================== Function Prototypes ======================================================================== */ void MEMiDumpUnitHeap( MEMHeapHandle heap ); MEMHeapHandle MEMCreateUnitHeapEx( void* startAddress, u32 heapSize, u32 memBlockSize, int alignment, u16 optFlag ); void* MEMDestroyUnitHeap ( MEMHeapHandle heap ); void* MEMAllocFromUnitHeap( MEMHeapHandle heap ); void MEMFreeToUnitHeap( MEMHeapHandle heap, void* memBlock ); u32 MEMCountFreeBlockForUnitHeap( MEMHeapHandle heap ); u32 MEMCalcHeapSizeForUnitHeap( u32 memBlockSize, u32 memBlockNum, int alignment ); /* ======================================================================= Inline Functions ======================================================================== */ /*---------------------------------------------------------------------------* Name: MEMCreateUnitHeap Description: Creates the unit heap. Arguments: startAddress: Start address of the heap area. heapSize: Size of the heap area. memBlockSize: Memory block size. Returns: If the function succeeds, a handle for the created unit heap is returned. If the function fails, NNS_FND_INVALID_HEAP_HANDLE is returned. *---------------------------------------------------------------------------*/ static inline MEMHeapHandle MEMCreateUnitHeap( void* startAddress, u32 heapSize, u32 memBlockSize ) { return MEMCreateUnitHeapEx( startAddress, heapSize, memBlockSize, MEM_HEAP_DEFAULT_ALIGNMENT, 0 ); } /*---------------------------------------------------------------------------* Name: MEMGetMemBlockSizeForUnitHeap Description: Gets the memory block size for the unit heap. Arguments: heap: Unit heap handle. Returns: Returns the memory block size for the unit heap. *---------------------------------------------------------------------------*/ static inline u32 MEMGetMemBlockSizeForUnitHeap( MEMHeapHandle heap ) { return ( ( (const MEMiUntHeapHead*)( (const u8*)heap + sizeof(MEMiHeapHead) ) )->mBlkSize ); } #ifdef __cplusplus } /* extern "C" */ #endif /* MEM_UNITHEAP_H__ */ #endif