• 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.

allocate

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,219
Hi I got a few questions on allocate and structs.
1. why do I need to use allocate in the constructor
2. do I need to have it in the constructor no mater what or only during certain conditions
3. how do I "deindex" a object from a struct? like when a unit dies I want to remove this.values from the struct to save memory.
4. how do I loop though all my objects inside a struct? I suspect you use some kind of list but I dont know what it's called in jass
 
  1. By default the .create method allocates an instance for you (by calling .allocate). If you override the create method you're expected to return an index for the struct. This index is usually generated by the allocate method, so this is why most people call it. You can however create your own allocation system and ignore .allocate() completely.
  2. Like I said in point 1, you don't have to but you definitely should have some allocation. For example you could just return 0 everytime in .create()
  3. You can override the onDestroy method or just call .destroy()
  4. You can use a linked list to store the indicies, or make the struct act as a linked list itself.
 
Status
Not open for further replies.
Top