A class to make saving and retrieving easier and more compact

There is a class provided that can make the saving and retrieving of data easy. You do not have to use it, but it useful in most cases. It is called CStaticStorage and is used like this:

@PUT_DATA_INTO_A_BYTE_ARRAY

// write data to abStatic

CStaticStorage ss(iApproximateSizeNeeded);

ss.Store(m_iFirstVariable);

ss.Store(m_abSecondVariable);

ss.RetrieveStream(abStatic);

@GET_DATA_FROM_A_BYTE_ARRAY

// read data from abStatic

CStaticStorage ss(abStatic);

ss.Get(m_iFirstVariable);

ss.Get(m_abSecondVariable);

There are two constructors, one for getting the data and one for putting the data. When putting the data, make a guess about how large the array will be and pass that to the constructor. That is for efficiency only. If you guess too low, then extra memory allocation will occur that will slow down the routine, and if you guess too high, then memory is wasted. That memory is recovered soon, though, so it is better to guess a little high.

Then make sure that the Get() and Store() functions are parallel; that is, the variables should be declared in the same order in both routines. Both of these routines are overloaded, so you can call them with many basic types: bool, int, char, int64, Abyte&, unsigned int, unsigned char, insigned int64. If you need to save another type, then you will have to break it down yourself and call these functions on the pieces.

The last line when saving the data is always ss.RetrieveStream(abStatic); This takes the saved data from the class and puts it into the real data object variable.

Beyond the ease of use, another advantage of this class is that it compresses the data as it saves it. For instance, if you have a 64-bit integer to save, it would take eight bytes to save it normally. This routine compresses it, so that depending on the contents of that field, only between one and eight bytes are required.