1 /*---------------------------------------------------------------------------*
2 Project: Dolphin OS Overview - One heap demo
3 File: allocdemo2-oneheap.c
4
5 Copyright 1998, 1999 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: allocdemo2-oneheap.c,v $
14 Revision 1.2 02/20/2006 04:13:11 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/13/2006 11:24:12 hiratsu
18 Initial check in.
19
20
21 3 6/11/99 10:07a Tianli01
22 Beautified
23
24 2 6/09/99 10:35a Hashida
25 Inserted OSRound*32B macros in OSCreateHeap() so that the local arenaHi
26 is consistent with the system corresponding variable after the second
27 OSSetArenaLo().
28
29 1 6/04/99 3:04p Tianli01
30 Initial check-in
31 $NoKeywords: $
32 *---------------------------------------------------------------------------*/
33
34 /*---------------------------------------------------------------------------*
35 This program shows how to set up and use one heap
36 *---------------------------------------------------------------------------*/
37
38 #include <revolution.h>
39
40 OSHeapHandle TheHeap;
41
42 #define INT_ARRAY_ENTRIES 1024
43
main()44 void main ()
45 {
46 void* arenaLo;
47 void* arenaHi;
48 u32* intArray;
49
50 OSInit();
51
52 OSReport("\n-----------------------------------");
53 OSReport("\n Hit Command+Q to quit this demo");
54 OSReport("\n-----------------------------------\n\n");
55
56 arenaLo = OSGetArenaLo();
57 arenaHi = OSGetArenaHi();
58
59 // OSInitAlloc should only ever be invoked once.
60 arenaLo = OSInitAlloc(arenaLo, arenaHi, 1); // 1 heap
61 OSSetArenaLo(arenaLo);
62
63 // The boundaries given to OSCreateHeap should be 32B aligned
64 TheHeap = OSCreateHeap((void*)OSRoundUp32B(arenaLo),
65 (void*)OSRoundDown32B(arenaHi));
66 OSSetCurrentHeap(TheHeap);
67 // From here on out, OSAlloc and OSFree behave like malloc and free
68 // respectively
69
70 OSSetArenaLo(arenaLo = arenaHi);
71
72 intArray = (u32*)OSAlloc(sizeof(u32) * INT_ARRAY_ENTRIES);
73
74 // some interesting code using intArray would go here
75
76 OSFree(intArray);
77
78 OSHalt("End of demo");
79 }
80