libretro / libretro-handy

K. Wilkins' Atari Lynx emulator Handy (http://handy.sourceforge.net/) for libretro
14 stars 35 forks source link

Improve save state efficiency #102

Closed jdgleaver closed 2 years ago

jdgleaver commented 2 years ago

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.