At present, the retro_serialize() function determines the save state size by allocating a temporary ~310kb buffer, writing an actual save state into it, then fetching the resultant buffer occupancy. This is terribly inefficient - and retro_serialize() is called 3 times every time a state is saved or loaded...
This PR modifies the serialisation memory stream code to allow a 'virtual' save state to be made - no buffer is required, and no data are copied. This means retro_serialize() can now fetch the save state size with no memory allocations and no wasted effort.
At present, the
retro_serialize()
function determines the save state size by allocating a temporary ~310kb buffer, writing an actual save state into it, then fetching the resultant buffer occupancy. This is terribly inefficient - andretro_serialize()
is called 3 times every time a state is saved or loaded...This PR modifies the serialisation memory stream code to allow a 'virtual' save state to be made - no buffer is required, and no data are copied. This means
retro_serialize()
can now fetch the save state size with no memory allocations and no wasted effort.