Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, Nymphodora), 1,012 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Declaring vars in loops [Re: txesmi] #468256
09/27/17 10:00
09/27/17 10:00
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
As long as the variable is only used within the loops body (and not expecting to keep its value over loop iterations), it's perfectly fine and the good way.


Visit my site: www.masterq32.de
Re: Declaring vars in loops [Re: MasterQ32] #468265
09/27/17 14:36
09/27/17 14:36
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
thank you for the indepth look into this friends.

When looking at the "variables" page in the manual, it describes the var types, short/char/var/int/float, and each of these is also described as size in bytes, which I assume is how much memory it requires to use. So if you declare boop before the while(1) loop, the engine allocated 8bytes of memory for this variable, and never has to allocate memory for this again.

But if you declare boop within a loop, is the engine continually adding 8bytes every frame?....which means if you leave it on long enough the engine would run out of memory lol, which I think doesnt happen.

Code:
action super_thing()
{
  while(1)
  { // Boop is "allocated" here
    var Boop; // Boop is undefined here
    Boop+=1*time_step; // add something to an undefined value will result in an undefined value
  } // Boop is "invalidated" here
}



this is where it made sense for me laugh Thank you

Re: Declaring vars in loops [Re: jumpman] #468270
09/27/17 16:12
09/27/17 16:12
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Quote:
But if you declare boop within a loop, is the engine continually adding 8bytes every frame?....which means if you leave it on long enough the engine would run out of memory lol, which I think doesnt happen.

No, this is not right. Allocation in this context is allocating stack memory which is released at the end of a block (which is a closing '}')


Visit my site: www.masterq32.de
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1