nestharus / JASS

MIT License
31 stars 8 forks source link

alloc, oninit loop seems to be not required #20

Closed Ruk33 closed 10 years ago

Ruk33 commented 10 years ago
static method allocate takes nothing returns integer
    local integer instance = recycle[0]

    if ( recycle[instance] == 0 ) then
        set recycle[0] = instance + 1
    else
        set recycle[0] = recycle[instance]
    endif

    return instance
endmethod

works without the init loop

nestharus commented 10 years ago

That still requires an onInit to store 1 into recycler[0], otherwise good job ^)^

You should also store 0 into instance 8191 to allocate the entire array

I personally like the loop since I rely on allocation for extremely heavy algorithms and need it to be as lightweight as possible to prevent threads from crashing ^)^. It'd be even better if it inlined o-o.

Ruk33 commented 10 years ago

it requires if you do -1, but if you use +1, you dont :D

nestharus commented 10 years ago

Elaborate please

Ruk33 commented 10 years ago

well there isn't that much to elaborate

http://www.hiveworkshop.com/forums/lab-715/allocation-one-variable-253320/

nestharus commented 10 years ago

How is the first instance you allocate not 0? Also, the array will be remade a lot cuz you don't set 8191.

nestharus commented 10 years ago

local integer instance = recycler[0] + 1

Ruk33 commented 10 years ago

right, recycle[0] + 1 should avoid first instance to be 0.

also, i was reading about array length on wc3, and apparently yes, its size will be changed several times, so should this matter?, is it an expensive operation?.

other way to avoid this would be set recycle[8190] = 1 || 0 on allocate.

nestharus commented 10 years ago

I'm going to implement this with credits to you. It will be standard Alloc.

the + 1 to first instance must be put in onInit or it will go 1, 3, 5 etc. I'll be sure to set last index to 0 too.

There will also be a fast version, or low op, which will be current module.

Thank you Ruk33. Sry i'm a bit slow right now :).

TriggerHappy upset me with his recent comment that he doesn't want to approve anything that requires Alloc -.-.

Ruk33 commented 10 years ago

You're welcome :).