Game Development Reference
In-Depth Information
The first line is the address of the MemoryAllocationHeader struct , which for our first call is also the
address stored in pMemoryHeap . The next line is the value stored in pStart , then pNextFree , then size .
These are all 0 as we have not yet made any allocations. The memory addresses are being printed as
32-bit hexadecimal values.
Our first Simple object is then allocated. It turns out that because the Simple class only contains
a single int variable, we only need to allocate 4 bytes to store it. The output from the second
PrintAllocations call confirms this.
Constructed
0x00870320
0x0087032C
0x00870330
4
0x00870330
0x00000000
0x00000000
0
We can see the Constructed text, which was printed in the constructor for the Simple class and then
that our first MemoryAllocationHeader struct has been filled in. The address of the first allocation
remains the same, as it is the beginning of the heap. The pStart variable stores the address from
12 bytes after the beginning as we have left enough space to store the header. The pNextFree
variable stores the address after adding the 4 bytes required to store the pSimple variable, and the
size variable stores the 4 from the size passed to new . We then have the printout of the first free
block, starting at 00870330 , which is conveniently 16 bytes after the first.
The program then allocates another two Simple objects to produce the following output.
Constructed
0x00870320
0x0087032C
0x00870330
4
0x00870330
0x0087033C
0x00870340
4
0x00870340
0x0087034C
0x00870350
4
0x00870350
0x00000000
0x00000000
0
 
Search WWH ::




Custom Search