Skip to content

Commit c4ecb36

Browse files
author
LoneWandererProductions
committed
cleanup my own mess
1 parent 1f69cb4 commit c4ecb36

4 files changed

Lines changed: 31 additions & 66 deletions

File tree

ExtendedSystemObjects/Helper/UnmanagedMemoryHelper.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,11 @@ internal static void Free(void* ptr)
8181
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8282
internal static void Clear<T>(T* buffer, int count) where T : unmanaged
8383
{
84-
<<<<<<< HEAD
85-
unsafe
86-
{
87-
Clear((T*)buffer, count);
88-
}
89-
}
90-
91-
/// <summary>
92-
/// Clears a block of unmanaged memory using a typed pointer.
93-
/// </summary>
94-
/// <typeparam name="T">The unmanaged value type used in the memory block.</typeparam>
95-
/// <param name="ptr">The PTR.</param>
96-
/// <param name="count">The count.</param>
97-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
98-
internal static unsafe void Clear<T>(T* ptr, int count) where T : unmanaged
99-
{
100-
new Span<T>(ptr, count).Clear();
101-
}
102-
103-
/// <summary>
104-
/// Shifts the right. Adding data at index.
105-
=======
10684
NativeMemory.Clear(buffer, (nuint)count * (nuint)sizeof(T));
10785
}
10886

10987
/// <summary>
11088
/// Shifts the right. Adding data at index.
111-
>>>>>>> f0801e635c3ba81f09f1576542ea953bd75ade08
11289
/// </summary>
11390
/// <typeparam name="T">Generic Parameter</typeparam>
11491
/// <param name="ptr">The PTR.</param>

ExtendedSystemObjects/UnmanagedArray.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,8 @@ public UnmanagedArray(int size)
5454
Capacity = size;
5555
Length = size;
5656

57-
<<<<<<< HEAD
58-
// Fixed the initialization assignment bug here
59-
_ptr = (T*)UnmanagedMemoryHelper.Allocate<T>(size);
60-
UnmanagedMemoryHelper.Clear<T>(_ptr, size);
61-
=======
6257
_ptr = (T*)UnmanagedMemoryHelper.Allocate<T>(size);
6358
UnmanagedMemoryHelper.Clear(_ptr, size);
64-
>>>>>>> f0801e635c3ba81f09f1576542ea953bd75ade08
6559
}
6660

6761
/// <summary>
@@ -198,27 +192,13 @@ public void Resize(int newSize)
198192

199193
if (newSize == Capacity) return;
200194

201-
<<<<<<< HEAD
202-
// Reallocate directly using the cast pointer
203-
var newBuffer = UnmanagedMemoryHelper.Reallocate<T>((IntPtr)_ptr, newSize);
204-
var newPtr = (T*)newBuffer;
205-
206-
if (newSize > Capacity)
207-
{
208-
// Utilize the new pointer Clear overload cleanly
209-
UnmanagedMemoryHelper.Clear<T>(newPtr + Capacity, newSize - Capacity);
210-
}
211-
212-
_ptr = newPtr;
213-
=======
214195
_ptr = UnmanagedMemoryHelper.Reallocate(_ptr, newSize);
215196

216197
if (newSize > Capacity)
217198
{
218199
UnmanagedMemoryHelper.Clear(_ptr + Capacity, newSize - Capacity);
219200
}
220201

221-
>>>>>>> f0801e635c3ba81f09f1576542ea953bd75ade08
222202
Capacity = newSize;
223203

224204
if (Length > newSize)
@@ -234,11 +214,7 @@ public void Resize(int newSize)
234214
public void Clear()
235215
{
236216
EnsureNotDisposed();
237-
<<<<<<< HEAD
238-
UnmanagedMemoryHelper.Clear<T>(_ptr, Length);
239-
=======
240217
UnmanagedMemoryHelper.Clear(_ptr, Length);
241-
>>>>>>> f0801e635c3ba81f09f1576542ea953bd75ade08
242218
}
243219

244220
/// <inheritdoc />
@@ -340,12 +316,8 @@ private void Dispose(bool disposing)
340316

341317
if (_ptr != null)
342318
{
343-
<<<<<<< HEAD
344-
Marshal.FreeHGlobal((IntPtr)_ptr);
345-
=======
346319
// Standardized with tracking allocation layers safely
347320
UnmanagedMemoryHelper.Free(_ptr);
348-
>>>>>>> f0801e635c3ba81f09f1576542ea953bd75ade08
349321
_ptr = null;
350322
}
351323

ExtendedSystemObjects/UnmanagedIntArray.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,32 @@ public IEnumerator<int> GetEnumerator()
7979
}
8080

8181
/// <inheritdoc />
82+
/// <summary>
83+
/// Returns an enumerator that iterates through a collection.
84+
/// </summary>
85+
/// <returns>
86+
/// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
87+
/// </returns>
8288
IEnumerator IEnumerable.GetEnumerator()
8389
{
8490
return GetEnumerator();
8591
}
8692

8793
/// <inheritdoc />
94+
/// <summary>
95+
/// Gets the current number of elements in the array.
96+
/// </summary>
8897
public int Length { get; private set; }
8998

9099
/// <inheritdoc />
100+
/// <summary>
101+
/// Gets or sets the <see cref="!:T" /> at the specified index.
102+
/// </summary>
103+
/// <value>
104+
/// The <see cref="!:T" />.
105+
/// </value>
106+
/// <param name="i">The i.</param>
107+
/// <returns>Value at index.</returns>
91108
/// <exception cref="T:System.IndexOutOfRangeException"></exception>
92109
public int this[int i]
93110
{
@@ -118,6 +135,10 @@ public int this[int i]
118135
}
119136

120137
/// <inheritdoc />
138+
/// <summary>
139+
/// Resizes the internal buffer to the new capacity.
140+
/// If newSize is smaller than current Length, Length is reduced.
141+
/// </summary>
121142
public void Resize(int newSize)
122143
{
123144
ArgumentOutOfRangeException.ThrowIfNegative(newSize);
@@ -147,6 +168,9 @@ public void Resize(int newSize)
147168
}
148169

149170
/// <inheritdoc />
171+
/// <summary>
172+
/// Clears the array by setting all elements to zero.
173+
/// </summary>
150174
public void Clear()
151175
{
152176
// No casting, no IntPtr, just pure native clearing.
@@ -253,12 +277,8 @@ public int IndexOf(int value)
253277
}
254278

255279
/// <summary>
256-
/// Inserts 'count' copies of 'value' at the given index.
280+
/// Inserts 'count' copies of 'value' at the given index.
257281
/// </summary>
258-
/// <param name="index">The index.</param>
259-
/// <param name="value">The value.</param>
260-
/// <param name="count">The count.</param>
261-
/// <exception cref="System.ArgumentOutOfRangeException">index</exception>
262282
public void InsertAt(int index, int value, int count = 1)
263283
{
264284
if (index < 0 || index > Length)
@@ -282,10 +302,8 @@ public void InsertAt(int index, int value, int count = 1)
282302
}
283303

284304
/// <summary>
285-
/// Removes multiple elements efficiently, given sorted indices.
305+
/// Removes multiple elements efficiently, given sorted indices.
286306
/// </summary>
287-
/// <param name="indices">The indices.</param>
288-
/// <exception cref="System.IndexOutOfRangeException"></exception>
289307
public void RemoveMultiple(ReadOnlySpan<int> indices)
290308
{
291309
EnsureNotDisposed();
@@ -342,20 +360,18 @@ public void RemoveMultiple(ReadOnlySpan<int> indices)
342360
}
343361

344362
/// <summary>
345-
/// Returns a Span over the used portion of the array.
363+
/// Returns a Span over the used portion of the array.
346364
/// </summary>
347-
/// <returns>A span representing the used portion of the array.</returns>
348365
public Span<int> AsSpan()
349366
{
350367
EnsureNotDisposed();
351368
return new Span<int>(_ptr, Length);
352369
}
353370

354371
/// <summary>
355-
/// Ensures capacity to hold at least minCapacity elements.
356-
/// Grows capacity exponentially if needed.
372+
/// Ensures capacity to hold at least minCapacity elements.
373+
/// Grows capacity exponentially if needed.
357374
/// </summary>
358-
/// <param name="minCapacity">The minimum capacity.</param>
359375
public void EnsureCapacity(int minCapacity)
360376
{
361377
if (minCapacity <= Capacity)

ExtendedSystemObjects/UnmanagedIntList.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ private void Dispose(bool disposing)
548548
}
549549

550550
/// <summary>
551-
/// Ensures the capacity of the internal buffer is at least the specified minimum size.
552-
/// Resizes the buffer if necessary by doubling its capacity or setting it to the minimum required size.
551+
/// Ensures the capacity of the internal buffer is at least the specified minimum size.
552+
/// Resizes the buffer if necessary by doubling its capacity or setting it to the minimum required size.
553553
/// </summary>
554554
/// <param name="min">The minimum capacity required.</param>
555555
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)