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

[vJASS] Deallocating arguments in a single loop

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

Suppose I have some struct with a few dozen fields, some primitive type and some non-primitive.

Is there any way to deallocate all of the fields without having N lines, where N is the number of fields I need to deallocate?

e.g.

Code:
for arg in args do:
  deallocate arg
endfor

Or has it never proven useful for VJASS to abstract a method/structs arguments to a list?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You can rewrite the destroy method :

JASS:
struct S

    integer i
    real r
    string s
    unit u

    method destroy takes nothing returns nothing
        call this.deallocate() // recycle index
        set this.i = 0
        set this.r = 0
        set this.s = null
        set this.u = null
    endmethod

endstruct

But yeah there is not any automatic stuff about that as far i know, could be useful indeed.
 
There isn't a way. You would need N lines.

Or has it never proven useful for VJASS to abstract a method/structs arguments to a list?

It could be useful, but that is a sort of abstraction that gives the user the impression that the underlying code is compact. When translated to regular JASS, it would still require nulling each element.

But anyway, if it is just about nulling, you really don't need to worry about it that much. When that index is reused, the members will be overwritten anyway (usually). You only need to null it for specific cases (e.g. if you have to check if something is null before instanciating) or if you are paranoid about the itty bitty memory leak from global references.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Well I think we all should know by now that VJASS is an abstraction which gets translated to JASS anyway, why not add on more layers of abstraction to make writing and reading easier?

@Dr Super Good

Yes that's correct, thanks for reminding me. Except in cases where I have to check if a struct is empty. I had some very odd cases where if I didn't manually reset the struct's primitive values it would cause some issues later on--I can't remember the exact details, as it was a very specific instance.
 
Well I think we all should know by now that VJASS is an abstraction which gets translated to JASS anyway, why not add on more layers of abstraction to make writing and reading easier?

Yes, but who?

sethmachine said:
Yes that's correct, thanks for reminding me. Except in cases where I have to check if a struct is empty. I had some very odd cases where if I didn't manually reset the struct's primitive values it would cause some issues later on--I can't remember the exact details, as it was a very specific instance.

That can happen when you have a variable that isn't initialized during create (but at some later point in time). So in that sense, it can have issues.

If you set every field to some initial value in the create method, you won't have that issue.
 
Status
Not open for further replies.
Top