22 * COPYRIGHT: See COPYING in the top level directory
33 * PROJECT: MemoryManager.Types
44 * FILE: ArenaList.cs
5- * PURPOSE: A resizable, unmanaged list backed by a MemoryArena .
5+ * PURPOSE: A resizable, unmanaged list backed by an IMemoryAllocator interface contract .
66 * Automatically handles growth and memory reclamation via handles.
77 * PROGRAMMER: Peter Geinitz (Wayfarer)
88 */
@@ -14,15 +14,15 @@ namespace MemoryManager.Types
1414{
1515 /// <summary>
1616 /// A high-performance, resizable list for unmanaged types that allocates
17- /// its internal buffer from a <see cref="MemoryArena "/>.
17+ /// its internal buffer from an <see cref="IMemoryAllocator "/>.
1818 /// </summary>
1919 /// <typeparam name="T">The unmanaged type to store.</typeparam>
2020 public sealed class ArenaList < T > : IDisposable where T : unmanaged
2121 {
2222 /// <summary>
2323 /// The arena
2424 /// </summary>
25- private readonly MemoryArena _arena ;
25+ private readonly IMemoryAllocator _arena ;
2626
2727 /// <summary>
2828 /// The priority
@@ -55,10 +55,18 @@ public sealed class ArenaList<T> : IDisposable where T : unmanaged
5555 public int Capacity => _capacity ;
5656
5757 /// <summary>
58- /// Initializes a new instance of the <see cref="ArenaList{T}"/> class.
58+ /// Initializes a new instance of the <see cref="ArenaList{T}" /> class.
5959 /// </summary>
60+ < << << << HEAD
61+ /// <param name="arena">The arena.</param>
62+ /// <param name="initialCapacity">The initial capacity.</param>
63+ /// <param name="priority">The priority.</param>
64+ /// <param name="hints">The hints.</param>
65+ public ArenaList( IMemoryAllocator arena , int initialCapacity = 8 , AllocationPriority priority = AllocationPriority . Normal , AllocationHints hints = AllocationHints . None )
66+ == == == =
6067 public ArenaList ( MemoryArena arena , int initialCapacity = 8 ,
6168 AllocationPriority priority = AllocationPriority . Normal , AllocationHints hints = AllocationHints . None )
69+ >>> >>> > f41cf23e1c66b3d2e4e393356f32f92443e0ab03
6270 {
6371 if ( initialCapacity < = 0 ) initialCapacity = 8 ;
6472
@@ -67,56 +75,60 @@ public ArenaList(MemoryArena arena, int initialCapacity = 8,
6775 _priority = priority ;
6876 _hints = hints ;
6977
70- // Allocate the initial contiguous block from the arena using explicit design parameters
7178 _handle = _arena . Allocate ( Unsafe . SizeOf < T > ( ) * _capacity , _priority , _hints ) ;
7279 }
7380
7481 /// <summary>
75- /// Gets or sets the element at the specified index via direct address reference tracking expressions .
82+ /// Gets the <see cref="T"/> at the specified index.
7683 /// </summary>
77- /// <remarks>
78- /// Warning: Avoid using this indexer heavily inside tight loops, as each invocation incurs a synchronization check.
79- /// For performance-critical iteration paths, extract a transient block layout using <see cref="AsSpan"/> instead.
80- /// </remarks>
84+ /// <value>
85+ /// The <see cref="T"/>.
86+ /// </value>
87+ /// <param name="index">The index.</param>
88+ /// <returns></returns>
8189 public ref T this [ int index ] => ref Get ( index ) ;
8290
8391 /// <summary>
84- /// Adds an item to the list, automatically growing the internal buffer if necessary .
92+ /// Adds the specified item .
8593 /// </summary>
94+ /// <param name="item">The item.</param>
8695 public void Add ( T item )
8796 {
8897 if ( Count == _capacity ) Grow ( ) ;
8998
90- // Resolve layout constraints safely and insert item at tracking high-water marks
9199 var span = _arena . GetSpan < T > ( _handle , _capacity ) ;
92100 span [ Count ++ ] = item ;
93101 }
94102
95103 /// <summary>
96- /// Returns a reference to the element at the specified index.
104+ /// Gets the specified index.
97105 /// </summary>
106+ /// <param name="index">The index.</param>
107+ /// <returns></returns>
108+ /// <exception cref="System.IndexOutOfRangeException">Index {index} is outside active boundaries.</exception>
98109 public ref T Get ( int index )
99110 {
100111 if ( index < 0 || index >= Count )
112+ < << << << HEAD
113+ throw new IndexOutOfRangeException ( $ "Index { index } is outside active boundaries.") ;
114+ = == == ==
101115 throw new IndexOutOfRangeException (
102116 $ "Index { index } is outside the active boundaries of the ArenaList (Count: { Count } ).") ;
117+ > >>> >>> f41cf23e1c66b3d2e4e393356f32f92443e0ab03
103118
104119 var span = _arena . GetSpan < T > ( _handle , _capacity ) ;
105120 return ref span [ index ] ;
106121 }
107122
108123 /// <summary>
109- /// Resets the count to zero. Note: Does not clear memory tracking until an arena cycle triggers maintenance .
124+ /// Clears this instance .
110125 /// </summary>
111- public void Clear ( )
112- {
113- Count = 0 ;
114- }
126+ public void Clear ( ) => Count = 0 ;
115127
116128 /// <summary>
117- /// Exposes a fast, direct raw hardware <see cref="Span{T}"/> over the active items list.
118- /// This completely bypasses inner index loops lock overhead constraints.
129+ /// Ases the span.
119130 /// </summary>
131+ /// <returns></returns>
120132 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
121133 public Span < T > AsSpan ( )
122134 {
@@ -125,29 +137,33 @@ public Span<T> AsSpan()
125137 }
126138
127139 /// <summary>
128- /// Doubles the capacity of the list by allocating a new handle and migrating data.
140+ /// Exposes a zero-allocation, struct-based enumerator.
141+ /// Allows clean 'foreach' loop compilation bypassing the managed Garbage Collector entirely.
142+ /// </summary>
143+ /// <returns>An enumerator for the list.</returns>
144+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
145+ public Span < T > . Enumerator GetEnumerator ( ) => AsSpan ( ) . GetEnumerator ( ) ;
146+
147+ /// <summary>
148+ /// Grows this instance.
129149 /// </summary>
130150 private void Grow ( )
131151 {
132152 var newCapacity = _capacity * 2 ;
133153 var newHandle = _arena . Allocate ( Unsafe . SizeOf < T > ( ) * newCapacity , _priority , _hints ) ;
134154
135- // Fetch structural views over original and destination arrays atomically
136155 var oldSpan = _arena . GetSpan < T > ( _handle , _capacity ) ;
137156 var newSpan = _arena . GetSpan < T > ( newHandle , newCapacity ) ;
138157
139- // Execute blazing fast bitwise memory migration copy operations
140158 oldSpan . CopyTo ( newSpan ) ;
141-
142- // Reclaim legacy positions within the parent lane array trackers instantly
143159 _arena . Free ( _handle ) ;
144160
145161 _handle = newHandle ;
146162 _capacity = newCapacity ;
147163 }
148164
149165 /// <summary>
150- /// Releases the unmanaged memory handle pool block back to the parent arena coordinator framework .
166+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources .
151167 /// </summary>
152168 public void Dispose ( )
153169 {
0 commit comments