AllocatorManager vs UnsafeUtility.Malloc, what should be used for custom native containers?

Got a question regarding AllocatorManager, and what its purpose for building custom native containers?
When AllocatorManager should be used, and when its better to use plain UnsafeUtility.Malloc?

From source it seems like AllocatorManager is some kind of higher level abstraction on top of direct Malloc, but then again no mentions in docs whether it should be used instead.

The only mention regarding UnsafeUtility.Malloc is here:

So, what to use, and when?

4 Likes

Judging by the API it seems to me that UnsafeUtility.Malloc( long size , int alignment , Allocator allocator ) is most basic, low-lewel and c-like option. Whereas AllocatorManager.Allocate( AllocatorHandle allocatorHandle , int itemSizeInBytes , int intalignmentInBytes , int items ) tries to be a little bit more accessible. Both are unsafe so the difference looks rather cosmetic beyond just targeting programmers with slightly different backgrounds.

I’m not really sure what they were thinking with the new allocator stuff. I think it originated from Tiny not having access to UnityEngine. So they moved some of the allocator stuff to C# to get more reuse it looks like. As tiny has to implement in C whatever is still left in C, which duplicates what is in UnityEngine.

That’s just a guess though.

I would probably use the new stuff as it seems they have standardized around that.

1 Like