You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Replace grouped Block[] arrays with flat native memory (Block*) for
single-indirection block access on the hot path
- Pre-compute alignment mask to avoid repeated subtraction in TryAllocate
- Add [module: SkipLocalsInit] to eliminate unnecessary zero-initialization
- Vectorize BinsDirectory.Initialize with Span.Fill instead of scalar loop
- Implement IDisposable to properly free native block buffer
- Make BlockLinks.Undefined a static readonly field
- Enable AggressiveInlining on AlignHelper.AlignUpOffset
- Remove artificial lock() from benchmark for accurate comparison
/// This is a TLSF (Two-Level Segregated Fit) allocator following the paper http://www.gii.upv.es/tlsf/files/papers/ecrts04_tlsf.pdf
19
-
///
19
+
///
20
20
/// But with the following modifications:
21
21
/// - We are relying on a backend allocator for the chunks.
22
22
/// - We are not storing the block headers in the allocated memory but in separate array as the memory allocated from chunks might not be accessible from CPU (e.g GPU).
23
-
///
23
+
///
24
24
/// With its backend allocator, this allocator is dynamic and its size can grow as needed. This allocator doesn't allocate memory by itself,
25
25
/// but use a backend allocator to allocate chunks of memory. It is agnostic of the backend allocator (that can allocate memory from RAM or GPU memory...etc.).
/// Note that this class is not thread safe and should be guarded by a lock if used in a multi-threaded environment.
30
30
/// The rationale is that this allocator can be used with Thread Local Storage (TLS) buffers that are not shared between threads and don't need locking.
31
31
/// </remarks>
32
-
publicsealedunsafeclassTlsfAllocator
32
+
publicsealedunsafeclassTlsfAllocator:IDisposable
33
33
{
34
34
privatereadonlyIMemoryChunkAllocator_context;
35
35
privatereadonlyuint_alignment;
36
+
privatereadonlyuint_alignmentMask;
36
37
privateUnsafeList<Chunk>_chunks;
37
-
privateUnsafeList<Block[]>_groupedBlocks;
38
+
privateBlock*_blocks;
38
39
privateint_blockCount;
40
+
privateint_blockCapacity;
39
41
privateint_indexToFirstAvailableBlock;
40
42
privateBinsDirectory_bins;
41
43
@@ -47,10 +49,6 @@ public sealed unsafe class TlsfAllocator
privateconstintMinAlignment=1<<(BaseBin0Log2-SubBinsLog2);// Minimum alignment is 64 bytes
49
51
50
-
privateconstintGroupedBlockCountLog2=10;// TODO: Should we make this configurable? (It might not help with optimizations in that case for indexing a block)
0 commit comments