• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Destroy variables

Status
Not open for further replies.
Level 9
Joined
Dec 21, 2006
Messages
490
hey there

i am trying to remove not used variables (depending on the mode).
using:
int variable = 0;
.
.
.
gv_variable = null;

now galaxy says implicit cast not allowed. so null is not of type variable.

since i have no pointer pointing on this variable i cannot destroy it at all?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Dynamic use of the heap is not allowed in galaxy. Everything that uses the heap must be defined at during map initialization and will persist until the map session ends.

Galaxy has 2 heaps
Code: This contains all galaxy virtual machine instructions. It should also contain any constant fields. This heap is created when the Galaxy script is compiled during map initialization and cannot be modified in anyway during a session.
Data: This only contains statically allocated variables. The position of the variables in the heap is allocated when the Galaxy script is compiled during map initialization and during the session new variables cannot be allocated as well as old variables cannot be de-allocated. These variables can be assigned any value at any time as long as the Galaxy allows it.

int variable = 0;
.
.
.
gv_variable = null;
"null" is not an integer constant. I think null is only valid from complex types (some kind of handle).

The only dynamic allocation you are allowed is of the stack. This acts as every other stack in every language does except I think it might not allow functions to dynamically place data to it (all local variables have to be declared at the function beginning like in old C and also must have a constant size (no variable sized local arrays)).
 
Level 9
Joined
Dec 21, 2006
Messages
490
it's null, at least the editor reconice it. NULL doesn't work at all.

unused variables are more or less leaks :d
btw triggers can be destroyed dynamically TriggerDestroy(name);
at least i can get rid of those.

i would give some rep but i cannot even as i earn some lately....
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
unused variables are more or less leaks :d
You can try recycling them to some extent, using them for many systems in a map after one system is done with them.

btw triggers can be destroyed dynamically TriggerDestroy(name);
at least i can get rid of those.
Yeh, this also is good as it frees the limited number of event sockets you have allowing new triggers to be hooked to those events.

Unless you have a substantial amount of unused variables, I highly doubt you'll notice any issues.
An even then the only issue might be you run out of heap space for new variables. The maximum heap size is finite, only a few MB and so cannot really be counted as a leak.
 
Status
Not open for further replies.
Top