- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
I know when you call struct.destroy() it sets up a free spot in the actual array of integers and so when a new struct is made, that spot can be used up.
But I am still confused on this behavior below. Suppose I have some data structure which has struct members (an array or another struct). I then make a local struct, and set it to that member. What happens when I call destroy on the local struct afterwards? Will it also be the same as calling destroy on that actual struct member?
I ask this because I've had some funny behavior with some code. When I use local structs and destroy them, my global structs get messed up (the data gets overwritten). When I stopped destroying the local structs, my global structs worked fine. So I am guessing that you should not call destroy on a local struct unless you want its "reference" destroyed also.
So, would these be equivalent then, since they are the same underlying pointer/integer in the array managing myStruct?
I know when you call struct.destroy() it sets up a free spot in the actual array of integers and so when a new struct is made, that spot can be used up.
But I am still confused on this behavior below. Suppose I have some data structure which has struct members (an array or another struct). I then make a local struct, and set it to that member. What happens when I call destroy on the local struct afterwards? Will it also be the same as calling destroy on that actual struct member?
I ask this because I've had some funny behavior with some code. When I use local structs and destroy them, my global structs get messed up (the data gets overwritten). When I stopped destroying the local structs, my global structs worked fine. So I am guessing that you should not call destroy on a local struct unless you want its "reference" destroyed also.
JASS:
function foo takes myStruct s returns nothing
local myStruct bar
set bar = s
call bar.destroy()
endfunction
So, would these be equivalent then, since they are the same underlying pointer/integer in the array managing myStruct?
JASS:
//s is some instance of myStruct
call foo(s)
call s.destroy()