298 6. Resources and the File System
U8* ConvertOffsetToPointer(U32 objectOffset,
U8* pAddressOfFileImage)
{
U8* pObject = pAddressOfFileImage + objectOffset;
return pObject;
}
The problem we encounter when trying to convert pointers into off sets,
and vice-versa, is how to fi nd all of the pointers that require conversion. This
problem is usually solved at the time the binary fi le is writt en. The code that
writes out the images of the data objects has knowledge of the data types and
classes being writt en, so it has knowledge of the locations of all the pointersAddresses:
Offsets:RAM Binary FileObject 1Object 2Object 3Object 40x00x2400x4A00x7F0Object 1Object 4Object 2Object 30x2A0800x2D7500x2F1100x32EE00x32EE00x2F1100x2A0800x4A00x2400x0Pointers converted
to offsets; locations
of pointers stored in
fix-up table.Fix-Up Table
0x2000x340
0x810Pointers to various
objects are present.3 pointersFigure 6.9. A pointer fi x-up table.Offsets: Addresses:Binary File RAMObject 1Object 2Object 3Object 40x00x2400x4A00x7F0Object 1Object 4Object 2Object 30x301000x303400x305A00x308 F0Figure 6.8. Contiguous resource fi le image, after it has been loaded into RAM.