File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -50,10 +50,10 @@ public sealed class UnmanagedStringPool : IDisposable
5050 private int totalFreeBlocks ; // Total number of free blocks in the pool
5151 private int totalFreeBytes ; // Running total of free bytes to avoid recalculation
5252
53- // Index free blocks by size for faster allocation
53+ // Index free blocks by size for faster allocation, keyed by block size
5454 private readonly SortedList < int , List < FreeBlock > > freeBlocksBySize = new ( DefaultCollectionSize ) ;
5555
56- // Central registry of allocated strings
56+ // Central registry of allocated , keyed by allocation ID
5757 private readonly Dictionary < int , AllocationInfo > allocations = new ( DefaultCollectionSize ) ;
5858
5959 /// <summary>
@@ -387,6 +387,11 @@ private static int AlignSize(int sizeBytes)
387387 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
388388 private PooledString RegisterAllocation ( IntPtr ptr , int lengthChars , int offset )
389389 {
390+ if ( lastAllocationId == int . MaxValue ) {
391+ // in the unlikely event we reach MaxValue (2 billion+ allocations) we cannot allocate more
392+ throw new OutOfMemoryException ( "Allocation overflow" ) ;
393+ }
394+
390395 ++ lastAllocationId ;
391396 allocations [ lastAllocationId ] = new ( ptr , lengthChars , offset ) ;
392397 return new ( this , lastAllocationId ) ;
You can’t perform that action at this time.
0 commit comments