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 discusses game programs when they create and use multiple heaps. 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, sound, system heap) 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 and allocate memory block from the 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. You can use the memory blocks allocated from a heap like 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 border="1"><CAPTION>Functions for Searching for Heaps which Memory Blocks Were Allocated From</CAPTION> 39<TR><TD>Function</TD><TD>Description</TD></TR> 40<TR><TD><A HREF="./Heap/MEMFindContainHeap.html"><CODE>MEMFindContainHeap</CODE></A></TD><TD>Searches for the heap which the specified memory block was allocated from and returns a handle to this heap.</TD></TR> 41<TR><TD><A HREF="./Heap/MEMFindParentHeap.html"><CODE>MEMFindParentHeap</CODE></A></TD><TD>Returns the parent heap handle if the parent heap containing the specified heap exists. Returns <CODE>MME_HEAP_INVALID_HANDLE</CODE> (a <CODE>NULL</CODE> value) if the heap does not exist.</TD></TR> 42</TABLE> 43 44<H2>Revision History</H2> 45<P>03/01/2006 Initial version.</P> 46</BODY> 47</HTML> 48