• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Question about allocate and deallocate

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
I see some people tried make this own allocators and deallocators to recycling structs, but doesn't the JassHelper already recycle them? Is something that still happening and there is something wrong with using that default functions (something strange because in that case the creator would have already added it) or that was a misunderstanding?

PD: If you can, can you pass me a tutorial to create a indexing system with recycling? because I didn't end to understand them.
 
The old build-in allocator and decallocator do their job. They manage the pool of available integers for struct inctaces.
Some wrote custom allocs, because they made a simpler, more elegant, or faster alogirhtm. But conceptually, it's the same.
The old build-in alloc thouch, probably still works with max 2^13-1 as max instance number, where it could be 2^15-1 for new versions, since array size was increased.
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
The old build-in allocator and decallocator do their job. They manage the pool of available integers for struct inctaces.
Some wrote custom allocs, because they made a simpler, more elegant, or faster alogirhtm. But conceptually, it's the same.
The old build-in alloc thouch, probably still works with max 2^13-1 as max instance number, where it could be 2^15-1 for new versions, since array size was increased.
Thank you for the answer, but what about this?
PD: If you can, can you pass me a tutorial to create a indexing system with recycling? because I didn't end to understand them.
I think you know something because I remember some time ago you passed something similar.
 
I believe you might mean linked list, what I linked, but alloc isn't exactly the same.

Here are alloc examples:
... but there are more and maybe simpler ones. But they all reach out for the same, providing integers until a miximum number (array limit), with ability to deallocate/recylce integers into the pool. And array limit is most likely still meant to be 8192 for old alloc systems, which should be a quick update of a number in code, if they don't use the constant [ljass]JASS_MAX_ARRAY_SIZE[/ljass].

Thank you for the answer, but what about this?
what do you mean?
 
allocate will return an integer between 1 and 8192 (or what ever limit is set).
The returned integer is lets say "in use", so alloc won't return an integer which is already in use.
So at maximum alloc can provide you max with 8k unique integers.

Now there is deallocate. It's called to recylce an integer to the alloc pool again, once you don't need it anymore.
So when you deallocate one integer, then now it can be used for allocation again in future.

So the whole alloc system is marely to provide unique integers always when you need it.
This is, because structs in vjass are integers in the background.
Struct members are arrays, and alloc gives us the unique index for the array for our instances/objects to use the array.

JASS:
struct Point // Point is a integer array, Point[]
    real x // is actually an array x[]
    real y // is it actually an array y[]
    static method create takes nothing returns thistype
        local thistype this = allocate()  // "this" will be an integer, uniquely used for the struct
        set this.x = 1
        set this.y = 2
        return this
    endmethod
endstruct
.. in background, if it's not vjass anymore, but pure jass, the create method looks like:
JASS:
this = 1
Point_x[this] = 1
Point_y[this] = 2
return this

So our struct instance "this" is just a unique index for the array.
The "Point_" prefix is just so the name x and y don't collide with other names x/y of other structs.

On "how" a alloc actually works in background, to provide always one unique integer is not really interesting for users and for me personally. They just want that it gives integers and recylced them if not needed anymore. But one can anaylse their code to get the tequnique.
There are simpler allocs that marely focus on the integer pool so it can be used, and complex ones, like the one linked by Nestharus, with huge overhead next to functionality. Providing more analysis and safety in case of errors.
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,852
On "how" a alloc actually works in background, to provide always one unique integer is not really interesting for users and for me personally. They just want that it gives integers and recylced them if not needed anymore. But one can anaylse their code to get the tequnique.
There are simpler allocs that marely focus on the integer pool so it can be used, and complex ones, like the one linked by Nestharus, with huge overhead next to functionality. Providing more analysis and safety in case of errors.
Basically that's what I asked, not how to use them, so ok, thank you anyway.
 
PurgeandFire explain and visualisized here the default allocation algorithm: What happens to structs internally?
Other allocs all are slightly different implemented though, trying to improve the algorithm, or having extra safety/debugging stuff. Next to the both above there are even more implementations:

the algorithms always slightly differs but they all do the same, and it's only useful to analyse them for writing own alloc imo.
 
Status
Not open for further replies.
Top