HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

.Create & .Allocate

09-29-2007, 09:37 AM#1
Malf
Collapse JASS:
struct blah
    integer i
endstruct

function blarg takes nothing returns nothing
local blah b1 = blah.create()
local blah b2 = blah.allocate()
endfunction

I'd just like to kindly ask what is the difference between .create() and .allocate() ?
09-29-2007, 09:45 AM#2
Hitchhiker
you can create a custom create method, there you have to you .allocate() to get a fresh new struct.
Collapse JASS:
struct blah
    integer i
    static method create takes integer i returns blah
        local blah b = blah.allocate()
        set b.i = i
        return b
    endmethod
endstruct

function blarg takes nothing returns nothing
    local blah b1 = blah.create(5)
endfunction
09-29-2007, 10:16 AM#3
Malf
Oh I see, but what's the difference between them?
09-29-2007, 10:23 AM#4
cohadar
allocate is private and can be used only inside struct methods.
create is public and if there is no one it will be automatically created.

allocate is dynamic method.
create is static method.
-- ups error, they are both static

You can also exend create to give it your custom arguments,
allocate cannot be changed.

Allocate should be only used inside custom create method.
The fact that you can do this: (use allocate outside of struct method)
Collapse JASS:
function blarg takes nothing returns nothing
local blah b1 = blah.create()
local blah b2 = blah.allocate()
endfunction
..is something I consider a design error in jasshelper
09-29-2007, 11:21 AM#5
Malf
Oh I see, thank you then cohadar. Repped of course.
09-29-2007, 01:09 PM#6
Vexorian
allocate is private and it has always been private, thus the function in your first post is impossible to make.

Edit: If you don't declare an static create method, then jasshelper makes one automatically for you, that just calls allocate() and is public. That's the difference.