/*---------------------------------------------------------------------------* Copyright (C) 2010-2011 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: blockHeap.h Programmers: k2 Copyright (C) 2005 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_BLOCKHEAP_H__ #define MEM_BLOCKHEAP_H__ #ifdef __cplusplus extern "C" { #endif #include #include /* ======================================================================== defines ======================================================================== */ #define MEM_BLKHEAP_BYTES_PER_BLOCK_TRACK 20 #define MEM_BLKHEAP_TRACK_GROUP_OVERHEAD 16 #define MEM_BLKHEAP_TRACKING_BYTES(numTrack) \ ((numTrack * MEM_BLKHEAP_BYTES_PER_BLOCK_TRACK) + MEM_BLKHEAP_TRACK_GROUP_OVERHEAD) /* ======================================================================== these are usually statically allocated ======================================================================== */ typedef struct _MEMBlockHeap { // must be first thing in structure MEMiHeapHead head; u8 null_block[MEM_BLKHEAP_TRACKING_BYTES(1)]; void * first_block; void * last_block; void * next_free_block; u32 num_free_blocks_left; } MEMBlockHeap; /* ======================================================================== functions ======================================================================== */ void MEMiDumpBlockHeap( MEMHeapHandle heap ); MEMHeapHandle MEMInitBlockHeap( MEMBlockHeap * tracking, void * start_addr, void * end_addr, void * init_track_mem, u32 init_track_mem_bytes, u16 optFlag ); int MEMAddBlockHeapTracking(MEMHeapHandle heap, void *track_mem, u32 track_mem_bytes); void* MEMDestroyBlockHeap ( MEMHeapHandle heap ); void* MEMAllocFromBlockHeapAt( MEMHeapHandle heap, void *place, u32 size ); void* MEMAllocFromBlockHeapEx( MEMHeapHandle heap, u32 size, int alignment ); void MEMFreeToBlockHeap( MEMHeapHandle heap, void* memBlock ); u32 MEMGetTrackingLeftInBlockHeap( MEMHeapHandle heap ); u32 MEMGetTotalFreeSizeForBlockHeap( MEMHeapHandle heap ); u32 MEMGetAllocatableSizeForBlockHeapEx( MEMHeapHandle heap, int alignment ); /* ======================================================================== inlines ======================================================================== */ static inline void * MEMAllocFromBlockHeap( MEMHeapHandle heap, u32 size ) { return MEMAllocFromBlockHeapEx( heap, size, MEM_HEAP_DEFAULT_ALIGNMENT ); } static inline u32 MEMGetAllocatableSizeForBlockHeap( MEMHeapHandle heap ) { return MEMGetAllocatableSizeForBlockHeapEx( heap, MEM_HEAP_DEFAULT_ALIGNMENT ); } #ifdef __cplusplus } /* extern "C" */ #endif /* MEM_UNITHEAP_H__ */ #endif