1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<HTML> 3<HEAD> 4<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5<META http-equiv="Content-Style-Type" content="text/css"> 6<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 8.0.0.0 for Windows"> 7<TITLE>Multi-Heap Management</TITLE> 8<LINK rel="stylesheet" type="text/css" href="../CSS/revolution.css"> 9</HEAD> 10<BODY> 11 12<H1>Multi-Heap Management</H1> 13<p> 14This considers the creation and use of multiple heaps in game programs. 15</p> 16 17<H2>Multi-Heaps</H2> 18<p> 19Various types of data are used in a game, such as graphics, music, and system data. Using multiple heaps (for example, a game heap, sound heap, system heap and so on) makes data management easier. Using multiple heaps in this way is referred to as multi-heaps. 20</p> 21 22<H2>Freeing Multi-Heap Memory</H2> 23<p> 24A programmer should know from which heap to allocate memory blocks. Therefore, the programmer can specify a particular heap and allocate a memory block from that heap. 25</p> 26<p> 27What about freeing memory blocks? If you allocated these memory blocks, you will know which heap you should return the memory blocks to. So which heap should memory blocks be returned to when they are freed by another programmer? Even in this case, determining which heap the memory blocks should be returned to is possible if the intended purpose of each heap among the multiple heaps is clear. However, what do you do if the memory block can be returned to multiple heaps? 28</p> 29 30<H2>Managing Heaps Using a Tree Structure</H2> 31<p> 32When you can’t determine where the memory block that is being freed was allocated, a method to search for the heap where the memory block was allocated would be convenient. To implement this method, you can manage the heaps with a tree structure. Why a tree structure? With it, you can use the memory blocks allocated from a heap as heap memory (a hierarchical heap structure). 33</p> 34<p> 35Using a tree structure to manage heaps, you can recursively check the heap memory region to check which heap the memory block was allocated from. The MEM library internally creates a hierarchical structure for each heap that it creates. There is also a function that searches for the heap that a memory block was allocated from. These functions are shown in the following table. 36</p> 37 38<TABLE class="api_list" border="1"> 39<CAPTION>Functions for Searching for Heaps which Memory Blocks Were Allocated From</CAPTION> 40<TR><TD><B>Functions</B></TD><TD><B>Functions</B></TD></TR> 41<TR><TH><A HREF="./Heap/MEMFindContainHeap.html"><CODE>MEMFindContainHeap</CODE></A></TH><TD>Searches for the heap which the specified memory block was allocated from and returns a handle to this heap.</TD></TR> 42<TR><TH><A HREF="./Heap/MEMFindParentHeap.html"><CODE>MEMFindParentHeap</CODE></A></TH><TD>Returns the parent heap handle if the parent heap containing the specified heap exists. Returns <CODE>MME_HEAP_INVALID_HANDLE</CODE> (a null value) if the heap does not exist.</TD></TR> 43</TABLE> 44 45<H2>Revision History</H2> 46<P> 472006/03/01 Initial version.<BR> 48</P> 49 50<hr><p>CONFIDENTIAL</p></body> 51</HTML> 52