• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] WC3 array size usage and Wurst

Status
Not open for further replies.
Level 2
Joined
Dec 16, 2011
Messages
12
As a preface I want to say that I never used much GUI and I definitely didn't use any JASS so this may be common wc3 knowledge.

Googling around revealed that creating a wc3 array will always create one of size 8192.
Does this mean that in Wurst if I use shorthand array initialization:
Code:
int array b = [1, 2, 3]
I am wasting 8000+ elements worth of memory?
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
> so this may be common wc3 knowledge.

Sort of. Array usage and limits are common wc3 knowledge, but wurst uses an allocator (arrays) which are not free. You haven't asked about that, but I'll give a brief explanation below.

> Googling around revealed that creating a wc3 array will always create one of size 8192.

That used to be true, but in the last year a patch increased this by quite a lot.

> I am wasting 8000+ elements worth of memory?

No. All arrays in jass/wurst use an underlying ArrayList (style of) array. It means that you're only consuming up to 2x the number of members that you've used.

You should also know that - relative to the cost of using jass natives/code - jass arrays are pretty fast/cheap. Even if you allocae 32,000 members in an array, that's still going to be cheaper than some small amount of CreateUnit() calls.

> but wurst uses an allocator (arrays) which are not free.

Wurst classes are not magic. When you do "let m = new MyClass()", you're getting:

- a new, unused pointer (integer), which is actually an index into a set of arrays
- this is why you can cast to int (let z = m castTo int)
- you can run out of allocation space for the MyClass family (too many new MyClass(), not enough destroy m)

Good luck and happy wursting
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Max array size is now 32768 actually.
Actually it is defined by JASS_MAX_ARRAY_SIZE. This is currently 32768 but may be subject to change in future patches. For this reason use JASS_MAX_ARRAY_SIZE when referencing the maximum array size, and not a hard coded constant.

Each index is 4 bytes so 32768 * 4 = ~130 kB. This is the worst case for each array declared. JASS arrays are dynamic arrays in that they resize the underlying buffer to meet the storage requirements. In most cases arrays should never reach anywhere close to their maximum size. It is worth noting that arrays will only ever expand in size, they will not contract as one cannot make indices unused after they have been used.

If this is a concern one can switch to Lua which has fully dynamic memory allocation support with garbage collection.
 
Last edited:
Level 2
Joined
Dec 16, 2011
Messages
12
Thanks for all your replies, they helped me get a better understanding.

Max array size is now 32768 actually.

All arrays in jass/wurst use an underlying ArrayList (style of) array.

Actually it is defined by JASS_MAX_ARRAY_SIZE

Are there good resources for information like this? A combination of World Editor Manual/API reference?
It feels like most of the google front page stuff was from the days when wc3 was very popular.
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
You can add a year to your google search terms to get more recent results. Or, you know, use the search feature on this site. Blizzard patch notes for the game also would have stated this but I get you wouldn’t think to look there.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
The patch notes should include important changes (but not all).
Problem is finding a log of all the patch notes. This used to be in a text file bundled with Warcraft III. However due to site and delivery changes it is very hard to track them down. Even searching hive news it is hard to get a consistent list due to how much news is posted.

In any case the JASS_MAX_ARRAY_SIZE information is now on Wikipedia. I updated the page about JASS
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
Thanks for all your replies, they helped me get a better understanding.

Are there good resources for information like this? A combination of World Editor Manual/API reference?
It feels like most of the google front page stuff was from the days when wc3 was very popular.

No. Tribal knowledge is everywhere.
 
Status
Not open for further replies.
Top