1 /*---------------------------------------------------------------------------*
2   Project:     MEM library
3   File:        allocator.h
4   Programmers: Takano Makoto
5 
6   Copyright 2005 Nintendo. All rights reserved.
7 
8   These coded instructions, statements, and computer programs contain
9   proprietary information of Nintendo of America Inc. and/or Nintendo
10   Company Ltd., and are protected by Federal copyright law.  They may
11   not be disclosed to third parties or copied or duplicated in any form,
12   in whole or in part, without the prior written consent of Nintendo.
13  *---------------------------------------------------------------------------*/
14 
15 #ifndef MEM_ALLOCATOR_H__
16 #define MEM_ALLOCATOR_H__
17 
18 #include <revolution/mem/heapCommon.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /* ========================================================================
25     Type Definitions
26    ======================================================================== */
27 
28 typedef struct MEMAllocator MEMAllocator;
29 
30 typedef void* (*MEMFuncAllocatorAlloc)( MEMAllocator* pAllocator, u32 size );
31 
32 typedef void  (*MEMFuncAllocatorFree) ( MEMAllocator* pAllocator, void* memBlock );
33 
34 typedef struct MEMAllocatorFunc MEMAllocatorFunc;
35 
36 struct MEMAllocatorFunc
37 {
38     MEMFuncAllocatorAlloc    pfAlloc;
39     MEMFuncAllocatorFree     pfFree;
40 };
41 
42 struct MEMAllocator
43 {
44     MEMAllocatorFunc const *  pFunc;
45     void*                     pHeap;
46     u32                       heapParam1;
47     u32                       heapParam2;
48 };
49 
50 
51 /* ========================================================================
52     Function Prototype
53    ======================================================================== */
54 
55 void*       MEMAllocFromAllocator( MEMAllocator* pAllocator, u32 size );
56 
57 void        MEMFreeToAllocator   ( MEMAllocator* pAllocator, void* memBlock );
58 
59 void        MEMInitAllocatorForExpHeap(
60                     MEMAllocator*    pAllocator,
61                     MEMHeapHandle    heap,
62                     int              alignment );
63 
64 void        MEMInitAllocatorForFrmHeap(
65                     MEMAllocator*    pAllocator,
66                     MEMHeapHandle    heap,
67                     int              alignment );
68 
69 void        MEMInitAllocatorForUnitHeap( MEMAllocator* pAllocator, MEMHeapHandle heap );
70 
71 void        MEMInitAllocatorForOSHeap ( MEMAllocator* pAllocator, OSHeapHandle heap );
72 
73 
74 #ifdef __cplusplus
75 } /* extern "C" */
76 #endif
77 
78 /* MEM_ALLOCATOR_H__ */
79 #endif
80