Refactored `AllocationManager` to introduce intrusive allocation tracking with `AllocationHeader` structs for debug mode. Added lightweight allocation counters for non-debug mode. Enhanced memory leak detection with detailed stack traces and `MemoryLeakException`. Simplified `AllocationInfo` by removing the `Allocator` property. Updated `AllocationOption` enum to remove `UnTracked` and clarified documentation. Improved unsafe collections (`UnsafeArray`, `UnsafeStack`, etc.) with strongly-typed enumerators and better compatibility with `IEnumerable<T>`. Enhanced `UnsafeStack` with a dedicated `Enumerator` struct and consistent constructor parameters. Refactored `MemoryLeakException` to support detailed allocation info and improved stack trace formatting. Simplified `MemoryUtility` by removing redundant null checks. Added unit tests for `AllocationManager`, `UnsafeArray`, and `UnsafeStack` to validate memory management and functionality. Updated `Program.cs` with new examples. Cleaned up namespaces, removed redundant `using` directives, and improved XML documentation. Applied `MethodImplOptions.AggressiveInlining` to performance-critical methods.
32 lines
1007 B
C#
32 lines
1007 B
C#
namespace Misaki.HighPerformance.LowLevel.Buffer;
|
|
|
|
[Flags]
|
|
public enum AllocationOption : byte
|
|
{
|
|
/// <summary>
|
|
/// Default allocation option. Values are uninitialized.
|
|
/// </summary>
|
|
None = 0,
|
|
/// <summary>
|
|
/// Clear the memory to zero upon allocation.
|
|
/// </summary>
|
|
Clear = 1 << 0,
|
|
}
|
|
|
|
public enum Allocator : byte
|
|
{
|
|
// Make the first allocator as invalid because we don't want to user create a default collection without passing any parameters
|
|
Invalid,
|
|
/// <summary>
|
|
/// Allocator for temporary allocations. Allocations are automatically released after use automatically.
|
|
/// </summary>
|
|
Temp,
|
|
/// <summary>
|
|
/// Allocator for persistent allocations. Allocations are not automatically released after use.
|
|
/// </summary>
|
|
Persistent,
|
|
/// <summary>
|
|
/// Allocator for stack allocations. Must have at least one active stack scope. Allocations are automatically released when the stack scope is exited.
|
|
/// </summary>
|
|
Stack
|
|
} |