mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-28 14:08:25 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
1 changed files with 768360 additions and 0 deletions
40
brutal.ktx/Brutal.Ktx/Abstractions/KtxNativeBuffer.cs
Normal file
40
brutal.ktx/Brutal.Ktx/Abstractions/KtxNativeBuffer.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
namespace Brutal.KtxApi;
|
||||
|
||||
/// <summary>
|
||||
/// Owns a native buffer returned by WriteToMemory/WriteKtx2ToMemory. The buffer is allocated with
|
||||
/// malloc() inside the native KTX library, so it must be freed with the matching native free() -
|
||||
/// Dispose() does this for you. Do not free the underlying pointer with any other allocator (e.g.
|
||||
/// Brutal.Memory.Mem.Free), as that frees memory with a different allocator than the one that
|
||||
/// allocated it, corrupting the heap.
|
||||
/// </summary>
|
||||
public unsafe struct KtxNativeBuffer : IDisposable
|
||||
{
|
||||
private byte* _pointer;
|
||||
|
||||
/// <summary>The size of the buffer in bytes.</summary>
|
||||
public ulong Length { get; }
|
||||
|
||||
/// <summary>Raw pointer to the native buffer.</summary>
|
||||
public byte* Pointer => _pointer;
|
||||
|
||||
/// <summary>
|
||||
/// A read-only view of the buffer. Throws if Length exceeds int.MaxValue, since Span<T>
|
||||
/// cannot address more than 2GiB - use Pointer and Length directly for buffers that large.
|
||||
/// </summary>
|
||||
public ReadOnlySpan<byte> Span => new(_pointer, checked((int)Length));
|
||||
|
||||
internal KtxNativeBuffer(byte* pointer, ulong length)
|
||||
{
|
||||
_pointer = pointer;
|
||||
Length = length;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_pointer is null)
|
||||
return;
|
||||
|
||||
KtxNativeMemory.Free(_pointer);
|
||||
_pointer = null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue