Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Freeing every single variable/array/function/procedure/imported files/pictures/etc
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
registration




PostPosted: Wed Jan 06, 2010 1:16 am   Post subject: Freeing every single variable/array/function/procedure/imported files/pictures/etc

Is there a single command to free every single thing that you initially declare at the start of the program? (e.g., when the game is over, you have an option to play again, but you have to reset the variables to the original values but it's easier to just free every memory location?)
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Jan 06, 2010 1:59 am   Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc

In general, you don't need to reset any variables to their original values. You need to close opened IO streams, and should probably Pic.Free() your images, though that's not necessary. Nothing else should be required, and no such command exists.
Zren




PostPosted: Wed Jan 06, 2010 2:18 am   Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc

Technically you program takes up memory, and the solution is to click that cool X then run the program again.

Theorectically, this would work. I'm not sure exactly since I seem to have a non-working compiler. Just compile this program to "test.exe".

Turing:

var input : string
put "Keep going? [Y/N]"
put "  > " ..
get input
if Str.Lower (input) = "y" then
    if not Sys.Exec ("text.exe") then
        put "The Sys.Exec call failed"
        put "Error: ", Error.LastMsg
    end if
end if
wtd




PostPosted: Wed Jan 06, 2010 4:51 am   Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc

Have your game state represented as an object. For a new game, you then only need to instantiate a new object.
mirhagk




PostPosted: Wed Jan 06, 2010 7:16 am   Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc

hey Zren so are you saying that at the end of the first game it should call itself again? (make sure that the original copy closes though)
Zren




PostPosted: Wed Jan 06, 2010 1:18 pm   Post subject: Re: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc

mirhagk @ Wed Jan 06, 2010 7:16 am wrote:
hey Zren so are you saying that at the end of the first game it should call itself again? (make sure that the original copy closes though)


Yes. It's not something that should be used yes, but it solves the question at hand. wtd definitely gave the correct method to program though.
Insectoid




PostPosted: Wed Jan 06, 2010 1:35 pm   Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc

You COULD, like, write a procedure that resets all variables to the default value and frees all pictures (and it SHOULD know what pictures exist, so freeing them shouldn't be a problem)? And then call that when the game resets? That's what I've always done.

It's important to filter out which variables need resetting and which don't matter.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: