Results 1 to 8 of 8

Thread: File Save To Memory?

  1. #1
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    637
    Rep Power
    83

    File Save To Memory?

    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.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: File Save To Memory?

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    637
    Rep Power
    83

    Re: File Save To Memory?

    Quote Originally Posted by Eros Olmi
    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
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  4. #4
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: File Save To Memory?

    Does someone have a thinBasic sample for this?

  5. #5
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    637
    Rep Power
    83

    Re: File Save To Memory?

    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.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: File Save To Memory?

    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.

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    637
    Rep Power
    83

    Re: File Save To Memory?

    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.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: File Save To Memory?

    ah, ah, that is tricky

    Happy to see it is working like you wanted
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Save File Glitch
    By JosephE in forum thinAir General
    Replies: 7
    Last Post: 26-04-2011, 15:41

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •