|
||
The following code fragments show an object or a C type struct being written to a file:
TXxx x; // some structure
TPtr8 xDes(&x, sizeof(x)); // descriptor of that structure
file.Write(xDes); // write structure to file
While this approach works, it is not type safe. The descriptor could be mistaken as referring to an object which is not of
type TXxx
.
Use a package buffer which works in a similar way but enforces type safety, as the following code fragment shows:
TXxx x; // some structure
TPckg<TXxx> xDes(x); // make into a package
file.Write(xDes); // now write structure t file