mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 04:58:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
1 changed files with 768360 additions and 0 deletions
62
brutal.core/Brutal.Core/Pointers/PointerExtensions.cs
Normal file
62
brutal.core/Brutal.Core/Pointers/PointerExtensions.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Brutal.Attributes;
|
||||
|
||||
namespace Brutal.Pointers.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for Span and ReadOnlySpan as pointers
|
||||
/// </summary>
|
||||
public static class PointerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the underlying pointer of span. Note this may be unsafe if the span refers to memory not allocated on the
|
||||
/// native memory, as they may be relocated at any time due to generational Garbage Collections. Please review usage
|
||||
/// to ensure only fixed native memory pointers are returned.
|
||||
/// </summary>
|
||||
/// <param name="span">Span of native memory</param>
|
||||
/// <returns>Unsafe pointer to block of memory</returns>
|
||||
public static unsafe T* AsPointer<T>(this Span<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
return (T*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the underlying pointer of span. Note this may be unsafe if the span refers to memory not allocated on the
|
||||
/// native memory, as they may be relocated at any time due to generational Garbage Collections. Please review usage
|
||||
/// to ensure only fixed native memory pointers are returned.
|
||||
/// </summary>
|
||||
/// <param name="span">ReadOnlySpan of native memory</param>
|
||||
/// <returns>Unsafe pointer to block of memory</returns>
|
||||
public static unsafe T* AsPointer<T>(this ReadOnlySpan<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
return (T*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the underlying pointer of span. Note this may be unsafe if the span refers to memory not allocated on the
|
||||
/// native memory, as they may be relocated at any time due to generational Garbage Collections. Please review usage
|
||||
/// to ensure only fixed native memory pointers are returned.
|
||||
/// </summary>
|
||||
/// <param name="span">Span of native memory</param>
|
||||
/// <returns>Unsafe pointer to block of memory</returns>
|
||||
public static unsafe Ptr<T> AsPtr<T>(this Span<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
return (T*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the underlying pointer of span. Note this may be unsafe if the span refers to memory not allocated on the
|
||||
/// native memory, as they may be relocated at any time due to generational Garbage Collections. Please review usage
|
||||
/// to ensure only fixed native memory pointers are returned.
|
||||
/// </summary>
|
||||
/// <param name="span">ReadOnlySpan of native memory</param>
|
||||
/// <returns>Unsafe pointer to block of memory</returns>
|
||||
public static unsafe Ptr<T> AsPtr<T>([Fixed] this ReadOnlySpan<T> span)
|
||||
where T : unmanaged
|
||||
{
|
||||
return (T*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue