Refactor to use MHP_ENABLE_SAFETY_CHECKS, MHP_ENABLE_STACKTRACE, and MHP_ENABLE_MIMALLOC for feature toggling. Remove FreeList allocator in JobSchedular and debug-layer code, simplifying memory management. Improve memory leak detection and reporting, update memory allocation API, and guard all safety/debug features with new defines. Update csproj files, README, and code samples to match new API and toggles. Fix and improve collection types for correct behavior with and without safety checks. The codebase is now more modular and easier to configure for different build environments. BREAKING CHANGE: Old defines (ENABLE_SAFETY_CHECKS, ENABLE_DEBUG_LAYER, ENABLE_MIMALLOC) are replaced with MHP_* equivalents. FreeList allocator and related debug features are removed. Some APIs and behaviors have changed for safety/debug configuration.
95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
|
|
namespace Misaki.HighPerformance.LowLevel.Collections.Contracts;
|
|
|
|
public unsafe interface IUnsafeCollection : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Indicates whether the object has been created. Returns true if the object is created, otherwise false.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If MHP_ENABLE_STACKTRACE is not defined, this property will only check if the underlying pointer is not null, which may not be sufficient to determine if the collection is fully initialized and ready for use.
|
|
/// </remarks>
|
|
bool IsCreated
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes all elements from the collection. The collection will be empty after this operation.
|
|
/// </summary>
|
|
void Clear();
|
|
|
|
/// <summary>
|
|
/// Returns a pointer to an unmanaged memory location. This pointer can be used for low-level memory operations.
|
|
/// </summary>
|
|
/// <returns>The method returns a void pointer to the unsafe memory location.</returns>
|
|
void* GetUnsafePtr();
|
|
}
|
|
|
|
public interface IUnsafeCollection<T> : IUnsafeCollection, IEnumerable<T>
|
|
where T : unmanaged
|
|
{
|
|
/// <summary>
|
|
/// Gets the number of elements in a collection.
|
|
/// </summary>
|
|
int Count
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes the size of a collection to the specified value.
|
|
/// </summary>
|
|
/// <remarks>This is to adjust the element count of the collection, not the size of the underlying buffer in memory.</remarks>
|
|
/// <param name="newSize">Specifies the new size to which the collection should be adjusted.</param>
|
|
/// <param name="option">Specifies allocation options that may affect how memory is managed during the resize operation.</param>
|
|
void Resize(int newSize, AllocationOption option);
|
|
}
|
|
|
|
public interface IUnsafeHashCollection<T> : IEnumerable<T>, IDisposable
|
|
where T : unmanaged
|
|
{
|
|
/// <summary>
|
|
/// Indicates whether the object has been created. Returns true if the object is created, otherwise false.
|
|
/// </summary>
|
|
bool IsCreated
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the number of elements in a collection. The value is read-only.
|
|
/// </summary>
|
|
int Count
|
|
{
|
|
get;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes all elements from the collection. The collection will be empty after this operation.
|
|
/// </summary>
|
|
void Clear();
|
|
|
|
/// <summary>
|
|
/// Changes the size of a collection to the specified value.
|
|
/// </summary>
|
|
/// <remarks>This is to adjust the element count of the collection, not the size of the underlying buffer in memory.</remarks>
|
|
/// <param name="newSize">Specifies the new size to which the collection should be adjusted.</param>
|
|
/// <param name="option">Specifies allocation options that may affect how memory is managed during the resize operation.</param>
|
|
void Resize(int newSize, AllocationOption option);
|
|
}
|
|
|
|
public interface IUnTypedCollection : IUnsafeCollection
|
|
{
|
|
/// <summary>
|
|
/// The total size of the buffer in bytes.
|
|
/// </summary>
|
|
nuint Size
|
|
{
|
|
get;
|
|
}
|
|
|
|
ref T GetElementAt<T>(nuint index)
|
|
where T : unmanaged;
|
|
} |