Phase 1: Object Allocator Diagrams (Handout)

These are the diagrams that were discussed in class and they assume a 32-bit computer (4-byte pointers): PDF File of the diagrams above.

Phase 2: More Details (These examples assume a 32-bit computer)

PDF File of the diagrams below.

Key to the signatures:

SignatureMeaning/UseOwned by
AAUnallocatedObjectAllocator
BBAllocatedClient/User
CCFreeObjectAllocator
DDPad bytesObjectAllocator
EEAlignment bytesObjectAllocator

To see what Real-World debuggers use, look here.

Key to the header blocks:

TypeMeaning/UseSize (bytes)
NoneNo header blocks are present0
Basic4-byte allocation number, 1-byte flags5
ExtendedBasic + 2-byte use count + user-defined bytesvaries
ExternalPointer to external data structuresizeof a pointer


Example 1: 16-byte data, no padding, no header blocks, no alignment, 3 objects per page.

FieldSize
Next pointer4 bytes
Padding0 bytes (not used)
Header block0 bytes (not used)
Data16 bytes
Alignment0/0 bytes (not used)
Page size52 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA B4 3D 33 00 AA AA AA AA AA AA AA AA
 AA AA AA AA C4 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 00 00 00 00 AA AA AA AA AA AA AA AA
 AA AA AA AA B4 3D 33 00 AA AA AA AA AA AA AA AA
 AA AA AA AA C4 3D 33 00 AA AA AA AA AA AA AA AA
 AA AA AA AA
Note: The data will naturally be aligned on 4-byte boundaries, due to the size of the data.


Example 2: 16-byte data, no padding, no header blocks, 8-byte alignment, 3 objects per page.

FieldSize
Next pointer4 bytes
Padding0 bytes (not used)
Header block0 bytes (not used)
Data16 bytes
Alignment4/0 bytes (left/interblock)
Page size56 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 EE EE EE EE 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA B8 3D 33 00 AA AA AA AA
 AA AA AA AA AA AA AA AA C8 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA 
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 EE EE EE EE 00 00 00 00 AA AA AA AA
 AA AA AA AA AA AA AA AA B8 3D 33 00 AA AA AA AA
 AA AA AA AA AA AA AA AA C8 3D 33 00 AA AA AA AA
 AA AA AA AA AA AA AA AA	

Note: Only the first block of data has alignment bytes. This is to ensure that the first block is aligned on an 8-byte boundary. The remaining blocks have no need for extra alignment bytes because they are already aligned on 8-byte boundaries. This is why there are two alignment fields in the OAConfig class: LeftAlignSize and InterAlignSize.


Example 3: 16-byte data, 2-byte padding (left/right), no header blocks, 8-byte alignment, 3 objects per page.

FieldSize
Next pointer4 bytes
Padding2 bytes
Header block0 bytes (not used)
Data16 bytes
Alignment2/4 bytes (left/interblock)
Page size74 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 EE EE DD DD 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD EE EE EE EE DD DD
 B8 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD EE EE EE EE DD DD D0 3D 33 00 AA AA AA AA
 AA AA AA AA AA AA AA AA DD DD
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 EE EE DD DD 00 00 00 00 AA AA AA AA
 AA AA AA AA AA AA AA AA DD DD EE EE EE EE DD DD
 B8 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD EE EE EE EE DD DD D0 3D 33 00 AA AA AA AA
 AA AA AA AA AA AA AA AA DD DD

Note: Both the LeftAlignSize and InterAlignSize values are non-zero. Also, each block has its own left and right pad bytes. The pad bytes are not shared between the blocks.


Example 4: 16-byte data, 2-byte padding (left/right), basic header blocks (5 bytes), 16-byte alignment, 3 objects per page.

FieldSize
Next pointer4 bytes
Padding2 bytes
Basic header block5 bytes
Data16 bytes
Alignment5/7 bytes (left/interblock)
Page size98 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 EE EE EE EE EE 00 00 00 00 00 DD DD 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD EE EE EE EE EE EE EE 00 00 00 00 00 DD DD C0 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD EE EE EE EE EE EE EE 00 00 00 00 00 DD DD E0 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 EE EE EE EE EE 00 00 00 00 00 DD DD
 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD EE EE EE EE EE EE EE 00 00 00 00 00 DD DD
 C0 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD EE EE EE EE EE EE EE 00 00 00 00 00 DD DD
 E0 3D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD
Note: Pay attention to the order of the alignment bytes, header block, and pad bytes. They are in that order from left to right in front of the data. The alignment bytes must take the header block and pad bytes into consideration.

Question: What is the size of the page? (Assumer 32-bit pointers)
Answer: It's the sum of all of the components. You are given all of the information in the constructor (via the configuration parameter) to calculate the page size.

  // next page pointer + left alignment block (only the first block has left alignment)
PageSize = sizeof(void *) + LeftAlignSize; // 4 + 5 = 9

  // Each object has a header, left padding, the object itself, right padding
  //   (The left and right padding blocks are the same size)
  //   3 * (5 + 2 + 16 + 2) = 75
PageSize += ObjectsPerPage * (HeaderSize + LeftPadSize + ObjectSize + RightPadSize);

  // All but the first block have an inter-block alignment block
PageSize += (ObjectsPerPage - 1) * InterAlignSize; // (3 - 1) * 7 = 14
Note that you are not given the alignment block sizes directly. You are given an alignment value, which is the alignment requirements for each block. From that, you must calculate the left-alignment and inter-alignment sizes. All of these calculations are done with simple math arithmetic as shown above.


Example 5: 16-byte data, 2-byte padding (left/right), extended header blocks with 1 additional byte (8 bytes), no alignment.

FieldSize
Next pointer4 bytes
Padding2 bytes
Extended header block8 bytes
Data16 bytes
Alignment0/0 no alignment
Page size88 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 00 00 00 00 00 00 00 00 DD DD 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD
 00 00 00 00 00 00 00 00 DD DD 8E 4D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD 00 00 00 00
 00 00 00 00 DD DD AA 4D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 00 00 00 00 00 00 00 00 DD DD 00 00
 00 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD
 00 00 00 00 00 00 00 00 DD DD 8E 4D 33 00 AA AA
 AA AA AA AA AA AA AA AA AA AA DD DD 00 00 00 00
 00 00 00 00 DD DD AA 4D 33 00 AA AA AA AA AA AA
 AA AA AA AA AA AA DD DD


Example 6: 16-byte data, 2-byte padding (left/right), external header blocks (4 bytes, 32-bit), 8-byte alignment.

FieldSize
Next pointer4 bytes
Padding2 bytes
External header block4 bytes
Data16 bytes
Alignment6/0 alignment
Page size82 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 EE EE EE EE EE EE 00 00 00 00 DD DD 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD 00 00 00 00 DD DD 90 4D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD 00 00 00 00 DD DD
 A8 4D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA DD DD
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 EE EE EE EE EE EE 00 00 00 00 DD DD
 00 00 00 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD 00 00 00 00 DD DD 90 4D 33 00 AA AA AA AA
 AA AA AA AA AA AA AA AA DD DD 00 00 00 00 DD DD
 A8 4D 33 00 AA AA AA AA AA AA AA AA AA AA AA AA
 DD DD


Example 7: 16-byte data, 2-byte padding (left/right), external header blocks (4 bytes, 32-bit), no alignment.

This example shows the dynamically-allocated structs and dynamically-allocated strings as well.

FieldSize
Next pointer4 bytes
Padding2 bytes
External header block4 bytes
Data16 bytes
Alignmentno alignment
Page size76 bytes

Memory dump (wrapped at 32 bytes):

  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 00 00 00 00 40 4E 33 00 DD DD BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB DD DD B8 4E 33 00 
 DD DD BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB DD DD 00 00 00 00 DD DD CC CC CC CC CC CC
 CC CC CC CC CC CC CC CC CC CC DD DD
Wrapped at 16 bytes:
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 00 00 00 00 40 4E 33 00 DD DD BB BB BB BB BB BB
 BB BB BB BB BB BB BB BB BB BB DD DD B8 4E 33 00 
 DD DD BB BB BB BB BB BB BB BB BB BB BB BB BB BB
 BB BB DD DD 00 00 00 00 DD DD CC CC CC CC CC CC
 CC CC CC CC CC CC CC CC CC CC DD DD
The diagram above is the result of allocating all 3 blocks, then freeing the right-most block. The signatures reflect this fact.

Note: The structs and the strings (labels) are dynamically allocated with new. Do not try and use your ObjectAllocator to manage that memory.