hgkjfhfdsj
Active Member
- Reaction score
- 55
i was looking through the jass conversion of a vjass code and i found a few questions/ in of further elaboration
what is the purpose of ....Data_F? i cant seem to see the logic behind the Data_F in the allocation process
initial value i saw was set to 0
ty.
EDIT
after rereading it i understood something.. i think..
correct me if im wrong. ive gathered that,
allocator works like a singly linked list (?):
V[this] holds either -1(in use), or the head's next node
I = index allocator
F = head of recycled indexes
EDIT2
found in (posted by nestharus) -- which allocator method would be most preferred for a vanilla jass user implementing pseudo/selfmade structs? .
JASS:
function s__MeatHook___Data__allocate takes nothing returns integer
local integer this=si__MeatHook___Data_F
if (this!=0) then
set si__MeatHook___Data_F=si__MeatHook___Data_V[this]
else
set si__MeatHook___Data_I=si__MeatHook___Data_I+1
set this=si__MeatHook___Data_I
endif
if (this>8190) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Unable to allocate id for an object of type: MeatHook___Data")
return 0
endif
set s__MeatHook___Data_extending[this]= false //fields
set s__MeatHook___Data_linknumber[this]=0 //fields
set si__MeatHook___Data_V[this]=-1
return this
endfunction
//Generated destructor of MeatHook___Data
function s__MeatHook___Data_deallocate takes integer this returns nothing
if this==null then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Attempt to destroy a null struct of type: MeatHook___Data")
return
elseif (si__MeatHook___Data_V[this]!=-1) then
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,1000.,"Double free of type: MeatHook___Data")
return
endif
set si__MeatHook___Data_V[this]=si__MeatHook___Data_F
set si__MeatHook___Data_F=this
endfunction
what is the purpose of ....Data_F? i cant seem to see the logic behind the Data_F in the allocation process
initial value i saw was set to 0
ty.
EDIT
after rereading it i understood something.. i think..
correct me if im wrong. ive gathered that,
allocator works like a singly linked list (?):
V[this] holds either -1(in use), or the head's next node
I = index allocator
F = head of recycled indexes
EDIT2
JASS:
globals
integer instanceCount = 0
integer array recycle
integer recycleCount = 0
endglobals
function allocate takes nothing returns integer
if (recycleCount != 0) then
set recycleCount = recycleCount - 1
return recycle[recycleCount]
endif
set instanceCount = instanceCount + 1
return instanceCount
endfunction
function deallocate takes integer this returns nothing
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
endfunction
found in (posted by nestharus) -- which allocator method would be most preferred for a vanilla jass user implementing pseudo/selfmade structs? .