View Full Version : File Save To Memory?
catventure
31-01-2010, 14:20
Hi,
Is it possible to save a binary file to memory (RAM) ?
I'm thinking of making a "ramsave" feature in my adventure game that would save the current game position and state of play (around 100k -200k) - without using file requester - but not to a physical file in the dir...
There would be an equivalent "ramload/quickload" input command so players could quickly restore their saved position. A lot of old adventure games used to have this feature.
Unsure how to proceed but presume would need to allocate the mem first and then write the data there? Then read it back when required.
Anyway, any help would be appreciated. Thanks.
Regards,
catventure.
ErosOlmi
31-01-2010, 14:24
catventure,
when you talk about save you mean that your application will end or will still be in memory?
If your application will end, any allocated memory will be released by the OS automatically. So I do not see any way to go that road.
If you application is still running, you can use any dynamic string variable or dynamic string variable array to store data up to 2GB for each string also taking advantages of string easy manipulation.
Eros
catventure
31-01-2010, 14:31
catventure,
when you talk about save you mean that your application will end or will still be in memory?
If your application will end, any allocated memory will be released by the OS automatically. So I do not see any way to go that road.
If you application is still running, you can use any dynamic string variable or dynamic string variable array to store data up to 2GB for each string also taking advantages of string easy manipulation.
Eros
Yes, application would still be running...
Never thought about using a string !
catventure
Michael Hartlef
31-01-2010, 14:49
Does someone have a thinBasic sample for this?
catventure
31-01-2010, 14:54
Thanks for your idea.
I already made an "undo" command which DOES use a savegameposition file and takes the player back ONLY ONE turn in the game to the state of play before they made their last move.... Very handy. I delete this file when necessary ie. when app ends or new game file loaded etc...
I think it will be easier to use a similar procedure for this kind of automatic quicksave file when the player wishes to temporarily save their position and then later on restore it to that previously saved point in time. By using a physical file, rather than one created and stored in memory, they could reload the game after eg: player death and then reinstate the saved game position...
The only difference there will between a normal savegameposition and this type of save is that it bypasses the file requester. That is really the ONLY difference now I think about it... so maybe not so good idea after all...
Anyway, I think I can modify my existing "save position" routine to accomplish it - or use your idea of large string with separator tokens.
Sorry - had late night last night - not thinking clearly - and rambling on a bit :)
Cheers,
catventure.
ErosOlmi
31-01-2010, 15:18
In dynamic strings you can store any kind of data, text and/or binary or whatever.
The only thing you have to do is to think how to store your data.
Another way could be to create your own structured data and use pointers and dynamic memory to allocate data when needed.
This road is a little more complicated but can give great flexibility.
catventure
31-01-2010, 20:47
I'm happy. By using a modification of my normal savegameposition function I now have it working how I wanted. So in next release of "thinbasic adventure builder" it will be possible for player to do an optional much quicker save game/load game eg:
'=========
You are on the bridge.
A troll is here.
What now?
>quicksave
OK.
What now?
>attack troll with carrot
The ugly troll brushes you away.
The troll advances toward you waving a short sword... Better do something quickly!
What now?
>quickload
You are on the bridge.
A troll is here.
'===========
Best wishes,
catventure.
ErosOlmi
31-01-2010, 20:54
ah, ah, that is tricky ;--)
Happy to see it is working like you wanted :D