This is smmalloc allocator version for Unity Engine with support of AllocatorManager.IAllocator and Unity.Collections.
smmalloc is a fast and efficient "proxy" allocator designed to handle many small allocations/deallocations in heavy multithreaded scenarios. The allocator created for using in applications where the performance is critical such as video games. Designed to speed up the typical memory allocation pattern in C++ such as many small allocations and deletions. This is a proxy allocator means that smmalloc handles only specific allocation sizes and pass-through all other allocations to generic heap allocator.
- Unity Burst: 1.8.8
- Unity Collections: 2.1.4
- Windows x64
// 8 buckets, 4 BM eachSmAllocatorUtility.Create(8,4*1024*1024,outvarallocator);SmAllocatorUtility.Destroy(refallocator);// buffer with 100 int elements (400 bytes memory block)varbuffer=SmAllocatorUtility.Malloc<int>(100,UnsafeUtility.SizeOf<int>(),UnsafeUtility.AlignOf<int>(),allocator.Handle);P.S.: Don't forget unsafe word!
SmAllocatorUtility.Free(100,buffer,allocator.Handle);P.S.: Don't forget unsafe word!
// NativeArray<T> with int 100 elementsvararray=SmAllocatorUtility.AllocateArray<int>(100,refallocator);SmAllocatorUtility.DisposeArray(refarray);For example NativeList:
// allocatevarnativeList=newNativeList<int>(allocator.Handle);// deallocatenativeList.Dispose();Or NativeHashSet:
// allocate with 10 initial capacityvarnativeHashSet=newNativeHashSet<int>(10,allocator.Handle);// deallocatenativeHashSet.Dispose();// create cache config with description (2048 bytes) for each allocator blockvarcacheConfig=Enumerable.Repeat(2048u,8).ToArray();// create thread cacheallocator.CreateThreadCache(cacheConfig,CacheWarmupOptions.CacheHot);allocator.DestroyThreadCache();