• 🏆 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!

[JASS] question about arrays

Status
Not open for further replies.
Level 2
Joined
Oct 5, 2004
Messages
12
Now that I UNDERSTAND Vexorian's handle variables it doesn't matter so much, but...

if you use indexes in an array, do all lower indices get memory allocated? In other words, if you were to do sth like use mod 1000 of a handle as the index value (and do what blizzard does with mpqs, and skip values if the desired one is full ^ ^ ), would you be wasting space?

i.e., you might be using spellTarget[17] and spellTarget[201] and spellTarget[724], but all the rest haven't been initialized yet. Are indices 723 on down still using up memory?

Related question: what happens if you start using a variable without assigning it a value?... (a type, yes, just no = .)

/me has many more questions, she justs wants to keep this post relatively on topic.. >.>
 
Level 3
Joined
Mar 27, 2004
Messages
70
Now that I UNDERSTAND Vexorian's handle variables it doesn't matter so much, but...
*grunts* Vex didn't invent the handle variables.

All arrays are 8192 (or something like that) wide and it shouldn't matter wether you use arr[8000] or arr[0], it uses the same amount of memory.
Unitialized variables can be used for comparison, but passing them to native functions will in often cause crashes.
A common pitfall is that people forget to initialize strings before writing something like set s = s + ".."
 
Level 2
Joined
Apr 13, 2004
Messages
29
That is not quite true, KaTTaNa. Arrays in War3 are not completely allocated at declaration. They are dynamic, as the memory usage will increase the higher entries you use. I think the space between highest used and lowest used array index is allocated but actually my last tests have been quite some time ago so it would not be bad to redo them and analyze the memory usage behavior of arrays.

Reading uninitialized variables causes the thread in which this happens to be cancelled.
 
Level 2
Joined
Apr 13, 2004
Messages
29
I tested it some time back and the memory usage of War3 increased the more I filled the array.
Of course it might not be a bad idea to repeat that test some time.
The maximum size might come from the way the dynamic array is implemented.
 
Level 2
Joined
Oct 5, 2004
Messages
12
By filling the array, do you mean assigning values to indexes between the highest and lowest, or assigning values to indexes higher than the previous highest...?

Another question! From blizzard.j,

function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
local group g = CreateGroup()
call GroupEnumUnitsInRect(g, r, filter)
call DestroyBoolExpr(filter)
return g
endfunction

So this leaks the handle reference? From what I understood about locals not getting un-referenced by a `return'...

Would it be possible (if you don't feel like using GroupEnumUnits..() directly...) to pass a group to a function call, and just return that parameter without leaking any memory? o.0

And while I'm at it, am I the only person for whom WE crashes when it tries to validate my code and I forgot to close an `if..' statement with endif? >.>
 
Level 2
Joined
Oct 5, 2004
Messages
12
Guys... I have another question...

when I run this code, every second:

JASS:
function trig_Actions takes nothing returns nothing
    local integer i = 1
    local location p1
    local location p2
    call ClearTextMessagesBJ(GetPlayersAll())
    loop
        exitwhen i > 1
        set p1 = Location(10, 10)
        call DisplayTextToForce( GetPlayersAll(), I2S( L2I( p1 )))
        call RemoveLocation(p1)
        set p1 = null
        set p2 = Location(10, 10)
        call DisplayTextToForce( GetPlayersAll(), I2S( L2I( p2 )))
        set udg_loc = Location(10, 10)
        call DisplayTextToForce( GetPlayersAll(), I2S( L2I( udg_loc )))
        //set p1 = GetLoc()
        //call DisplayTextToForce( GetPlayersAll(), I2S( L2I( p1 )))
        call DisplayTextToForce( GetPlayersAll(), "--------")
        set i = i + 1
        if i == 2 then
            call RemoveLocation(p2)
            set p2 = null
            call RemoveLocation(udg_loc)
        endif
    endloop
    //return
endfunction

(the loop was from another test)

Anyway... with the `set p1 = null' and `set p2' = null statements, I get repeating strings for the handle pointer values. When I take them out, tho, only the pointer value for the global is reused. Is this consistent with how we think functions work?

I read the original thread on memory leaks, the one where you guys did all the experiments with return values and setting to null.. but I don't know if you addressed this issue in another thread or not.

edit: n/m, question answered... should I just delete this post? >.>
 
Status
Not open for further replies.
Top