Structs Versus Locals

wraithseeker

Tired.
Reaction score
122
So.. I want to ask , which is more efficent? Structs do not need to be cleaned up but locals have to be.

E.g

JASS:
Local unit a = footman
set a = null


Structs

JASS:
private struct data
unit a

static method create takes nothing returns data
local data d = data.allocate()
set d.a = footman
endmethod
endstruct

private function actions takes nothing returns nothing
local data d = data.create()
endfunction


As u can see , the struct part doesn't need to be nulled / cleaned?

Right now i am puzzled to whether i should only use locals for things that do not need to be nulled e.g reals, integer , etc....

I am currently only using structs for things that need to be nulled, is that correct?
 

Kenny

Back for now.
Reaction score
202
I think you should just stick to locals if you do not need to pass data through timers or whatever.

Just because something needs to be nulled, doesn't necessarily mean that it is inefficient or bad.

Struct members don't need to be nulled because they are overridden when another instance begins (and one of the earlier have finished). Also, there is no reason why you dont have to null struct members. I do it out of habit now... once i initialise a variable (like a unit or something) i just null it when im finished to be safe.
 

Azlier

Old World Ghost
Reaction score
461
Structs are here for encapsulation. Need to store a whole lotta data on one unit? Struct it! Need to pass lots of data though a timer? Struct it!

Just use locals if you don't need to pass things around. Structs take two function calls to destroy and create, so it all works out using locals. (Note, structs may have extra function calls built in, such as .allocate which is called on .create. That makes three function calls!)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top