1)Offset is the distance from the start of the 'name' field to the end of the structure. The string data itself is written to the file after the structure, so the offset tells you how far forward in the file to jump in order to find the string.The usual way of using in-place memory offsets:
1) int offset = int((char*)(&object+1) - (char*)(&object.name)); //offset address is now between bar and baz?
2) object->name = ((char*)&object->name) + int(object->name);//did you mean offset?
2) Upon deserialisation, 'name' actually contains the above offset value, not a pointer. The offset is relative to the address of the 'name' field, so the address of 'name' is added to the integer value of 'name', resulting in a pointer to the string data.
small problem:
struct LOADSPRITEOBJECT
{
char* name;
D3DCOLOR Color;
D3DXVECTOR3 OffsetPosition;
bool visible;
};
int offset = int((char*)(&object+1) - (char*)(&object.name)); write( &offset, sizeof(int) );
What happens is that (char*)(&object+1) - (char*)(&object.name) lands you exactly 3 bytes too far. This is because it assumes that there is only a (char*) written (1 Byte) when there is actually 4 bytes written (int). You must subract 3 bytes from offset.






