Rxmxnx.PInvoke.Extensions
is a comprehensive library designed to streamline and enhance the
interaction between .NET and native P/Invoke methods.
- UTF-8/ASCII String Handling: Seamlessly work with UTF-8 encoded strings in interop contexts.
- Managed Buffers: Dynamically allocate object references on the stack with minimal effort.
- Safe Memory Manipulation: Eliminate direct pointer manipulation and unsafe code requirements.
Install the library via NuGet:
dotnet add package Rxmxnx.PInvoke.Extensions
Note: This package currently supports .NET 6 and higher. Ensure your project targets a compatible framework before installing.
Rxmxnx.PInvoke.Extensions
provides abstractions for managed handling of references and
fixed memory segments.
These interfaces represent a safe way to access a managed reference of a specific type.
IReadOnlyReferenceable<T>
This interface exposes a read-only reference to an object of type T
, allowing the object
to be used without modification.
Note: This interface inherits from IEquatable<T>
. This type allows public implementation or inheritance.
-
Reference
Gets the read-only reference to the instance of an object of type
T
.
IReferenceable<T>
This interface exposes a reference to an object of type T
,
allowing the object to be used and potentially modified.
Note: This interface inherits from IReadOnlyReferenceable<T>
. This type allows public implementation or
inheritance.
-
Reference
Gets the reference to the instance of an object of type
T
.
These interfaces represent a safe way to access a value or managed object of a specific type.
IWrapper<T>
This interface defines a wrapper for a T
object.
Note: This interface inherits from IEquatable<T>
. This type allows public implementation or inheritance.
-
Value
The wrapped
T
object.
-
Create(T?)
Creates a new instance of an object that implements
IWrapper<T>
interface.
IWrapper
is a non-generic interface that exposes static methods for creating specific types of
IWrapper<T>
for concrete cases of value types, nullable values, and non-nullable reference types.
-
Create<TValue>(TValue)
Creates a new instance of an object that implements
IWrapper<TValue>
interface.Note:
TValue
generic type isstruct
. -
CreateNullable<TValue>(TValue?)
Creates a new instance of an object that implements
IWrapper<TValue?>
interface.Note:
TValue
generic type isstruct
. -
CreateObject<TObject>(TObject)
Creates a new instance of an object that implements
IWrapper<TObject>
interface.Note:
TObject
generic type is areference type
.
IMutableWrapper<T>
This interface defines a wrapper for an object whose value can be modified.
Note: This interface inherits from IWrapper<T>
. This type allows public implementation or inheritance.
-
Value
The wrapped
T
object.
-
Create(T?)
Creates a new instance of an object that implements
IMutableWrapper<T>
interface.
IMutableWrapper
is a non-generic interface that exposes static methods for creating specific types of
IMutableWrapper<T>
for concrete cases of value types, nullable values, and non-nullable reference types.
-
Create<TValue>(TValue)
Creates a new instance of an object that implements
IMutableWrapper<TValue>
interface.Note:
TValue
generic type isstruct
. -
CreateNullable<TValue>(TValue?)
Creates a new instance of an object that implements
IMutableWrapper<TValue?>
interface.Note:
TValue
generic type isstruct
. -
CreateObject<TObject>(TObject)
Creates a new instance of an object that implements
IMutableWrapper<TObject>
interface.Note:
TObject
generic type is areference type
.
IMutableReference<T>
This interface exposes a wrapper for T
object that can be referenced and whose value can be modified.
Note: This interface inherits from IMutableWrapper<T>
and IReferenceable<T>
. This type allows public
implementation or
inheritance.
-
Reference
Reference to
T
wrapped instance.
-
Create(T?)
Creates a new instance of an object that implements
IMutableReference<T>
interface.
IMutableReference
is a non-generic interface that exposes static methods for creating specific types of
IMutableReference<T>
for concrete cases of value types, nullable values, and non-nullable reference types.
-
Create<TValue>(TValue)
Creates a new instance of an object that implements
IMutableReference<TValue>
interface.Note:
TValue
generic type isstruct
. -
CreateNullable<TValue>(TValue?)
Creates a new instance of an object that implements
IMutableReference<TValue?>
interface.Note:
TValue
generic type isstruct
. -
CreateObject<TObject>(TObject)
Creates a new instance of an object that implements
IMutableReference<TObject>
interface.Note:
TObject
generic type is areference type
.
These interfaces represent a safe way to access a fixed address of native or managed memory.
IFixedPointer
Interface representing a pointer to a fixed block of memory.
Note: This type allows public implementation or inheritance.
-
Pointer
Gets the pointer to the fixed block of memory.
IFixedPointer.IDisposable
representing a disposable IFixedPointer
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IFixedPointer
and System.IDisposable
. This type allows public implementation
or
inheritance.
IFixedMethod<TMethod>
Interface representing a method whose memory address is fixed in memory.
Note: This interface inherits from IFixedPointer
. This type allows public implementation or inheritance.
-
Method
Gets the delegate that points to the fixed method in memory.
IReadOnlyFixedMemory
Interface representing a read-only fixed block of memory.
Note: This interface inherits from IFixedPointer
. This type allows public implementation or inheritance.
-
Bytes
Gets a read-only binary span over the fixed block of memory. -
Objects
Gets a read-only object span over the fixed block of memory.
-
AsBinaryContext()
Creates a new instance of
IReadOnlyFixedContext<Byte>
from the current instance. -
AsObjectContext()
Creates a new instance of
IReadOnlyFixedContext<Object>
from the current instance.
IReadOnlyFixedMemory.IDisposable
representing a disposable IReadOnlyFixedMemory
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IReadOnlyFixedMemory
and IFixedPointer.IDisposable
. This type allows public
implementation or inheritance.
IReadOnlyFixedMemory<T>
Interface representing a read-only fixed block of memory for a specific type.
Note: This interface inherits from IReadOnlyFixedMemory
. This type allows public implementation or inheritance.
-
ValuePointer
Gets the value pointer to the read-only fixed block of memory. -
Values
Gets a read-only
T
span over the fixed block of memory.
IReadOnlyFixedMemory<T>.IDisposable
representing a disposable IReadOnlyFixedMemory<T>
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IReadOnlyFixedMemory<T>
and IReadOnlyFixedMemory.IDisposable
. This type
allows
public implementation or inheritance.
IFixedMemory
Interface representing a fixed block of memory.
Note: This interface inherits from IReadOnlyFixedMemory
. This type allows public implementation or inheritance.
-
Bytes
Gets a binary span over the fixed block of memory. -
Objects
Gets an object span over the fixed block of memory.
-
AsBinaryContext()
Creates a new instance of
IFixedContext<Byte>
from the current instance. -
AsObjectContext()
Creates a new instance of
IFixedContext<Object>
from the current instance.
IFixedMemory.IDisposable
representing a disposable IFixedMemory
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IFixedMemory
and IReadOnlyFixedMemory.IDisposable
. This type allows public
implementation or inheritance.
IFixedMemory<T>
Interface representing a fixed block of memory for a specific type.
Note: This interface inherits from IReadOnlyFixedMemory<T>
and IFixedMemory<T>
. This type allows public
implementation
or inheritance.
-
ValuePointer
Gets the value pointer to the fixed block of memory. -
Values
Gets a
T
span over the fixed block of memory.
IFixedMemory<T>.IDisposable
representing a disposable IFixedMemory<T>
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IReadOnlyFixedMemory<T>
and IFixedMemory.IDisposable
. This type allows public
implementation or inheritance.
IReadOnlyFixedReference<T>
This interface exposes a read-only reference to an object of type T, allowing the object to be used without modification.
Note: This interface inherits from IReadOnlyReferenceable<T>
and IReadOnlyFixedMemory
. This type allows public
implementation or inheritance.
-
Transformation(out IReadOnlyFixedMemory)
Reinterprets the read-only
T
fixed memory reference as a read-onlyTDestination
memory reference.
IReadOnlyFixedReference<T>.IDisposable
representing a disposable IReadOnlyFixedReference<T>
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IReadOnlyFixedReference<T>
and IReadOnlyFixedMemory.IDisposable
. This type
allows
public implementation or inheritance.
IFixedReference<T>
This interface represents a mutable reference to a fixed memory location.
Note: This interface inherits from IReferenceable<T>
, IReadOnlyFixedReference<T>
and IFixedMemory
. This type
allows
public implementation or inheritance.
-
Transformation(out IFixedMemory)
Reinterprets the
T
fixed memory reference as aTDestination
memory reference. -
Transformation(out IReadOnlyFixedMemory)
Reinterprets the
T
fixed memory reference as aTDestination
memory reference.
IFixedReference<T>.IDisposable
representing a disposable IFixedReference<T>
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IFixedReference<T>
and IReadOnlyFixedReference<T>.IDisposable
. This type
allows
public implementation or inheritance.
IReadOnlyFixedContext<T>
Interface representing a context from a read-only block of fixed memory.
Note: This interface inherits from IReadOnlyFixedMemory<T>
. This type allows public implementation or inheritance.
-
Transformation(out IReadOnlyFixedMemory)
Reinterprets the
T
fixed memory block asTDestination
memory block.
IReadOnlyFixedContext<T>.IDisposable
representing a disposable IReadOnlyFixedContext<T>
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IReadOnlyFixedContext<T>
and IReadOnlyFixedMemory<T>.IDisposable
. This type
allows
public implementation or inheritance.
IFixedContext<T>
Interface representing a context from a block of fixed memory.
Note: This interface inherits from IReadOnlyFixedContext<T>
and IFixedMemory<T>
. This type allows public
implementation
or inheritance.
-
Transformation(out IFixedMemory)
Reinterprets the
T
fixed memory block as aTDestination
memory block. -
Transformation(out IReadOnlyFixedMemory)
Reinterprets the `T` fixed memory block as a `TDestination` memory block.
IFixedContext<T>.IDisposable
representing a disposable IFixedContext<T>
object.
This interface is used for managing fixed memory blocks that require explicit resource cleanup.
Note: This interface inherits from IFixedContext<T>
and IFixedMemory<T>.IDisposable
. This type allows public
implementation or inheritance.
These interfaces expose functionalities for internal types or default functional implementations.
IEnumerableSequence<T>
Defines methods to support a simple iteration over a sequence of a specified type.
Note: This interface inherits from IEnumerable<T>
. This type allows public implementation or inheritance.
-
GetItem(Int32)
Retrieves the element at the specified index. -
GetSize()
Retrieves the total number of elements in the sequence.
-
DisposeEnumeration(Int32)
Method to call when
IEnumerator<T>
is disposing.
IUtf8FunctionState<TSelf>
Interface representing a value state for functional CString creation.
Note: TSelf
generic type is struct
. This type allows public implementation or inheritance.
-
IsNullTerminated
Indicates whether resulting UTF-8 text is null-terminated.
-
GetSpan(TSelf)
Retrieves the span from state. -
GetLength(in TSelf)
Retrieves the span length from state.
IManagedBuffer<T>
This interfaces exposes a managed buffer.
Note: This type not allow public implementation or inheritance.
-
GetMetadata<TBuffer>()
Retrieves the
BufferTypeMetadata<T>
instance fromTBuffer
.
IManagedBinaryBuffer<T>
This interfaces exposes a binary managed buffer.
Note: This interface inherits from IManagedBuffer<T>
. This type not allow public implementation or inheritance.
-
Metadata<TBuffer>()
Retrieves the
BufferTypeMetadata<T>
instance from current instance.
IManagedBinaryBuffer<TBuffer, T>
This interfaces exposes a binary managed buffer.
Note: TBuffer
generic type is struct
. This interface inherits from IManagedBinaryBuffer<T>
. This type not
allow
public implementation or inheritance.
These delegates encapsulate methods that operate with Span instances.
ReadOnlySpan<T> ReadOnlySpanFunc<T>()
Encapsulates a method that has no parameters and returns a read-only span of type T
.
ReadOnlySpan<T> ReadOnlySpanFunc<T, in TState>(TState)
Encapsulates a method that has a TState
parameter and returns a read-only span of type T.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult SpanFunc<T, in TArg, out TResult>(Span<T>, TArg)
Encapsulates a method that receives a span of type T
, a state object of type TArg
and returns a result of type
TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult ReadOnlySpanFunc<T, in TArg, out TResult>(Span<T>, TArg)
Encapsulates a method that receives a read-only span of type T
, a state object of type TArg
and returns a result
of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that operate with fixed memory blocks.
void FixedAction(in IFixedMemory)
Represents an action that operates on a fixed memory instance.
void FixedAction<in TArg>(in IFixedMemory, TArg)
Represents an action that operates on a fixed memory instance using an additional state object.
Note: In .NET 9.0+ TState
allows ref struct
.
void ReadOnlyFixedAction(in IReadOnlyFixedMemory)
Represents an action that operates on a read-only fixed memory instance.
void ReadOnlyFixedAction<in TArg>(in IReadOnlyFixedMemory, TArg)
Represents an action that operates on a read-only fixed memory instance using an additional state object.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult FixedFunc<out TResult>(in IFixedMemory)
Represents a function that operates on a fixed memory instance.
TResult FixedFunc<in TArg, out TResult>(in IFixedMemory, TArg)
Represents a function that operates on a fixed memory instance using an additional state object.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult ReadOnlyFixedFunc<out TResult>(in IReadOnlyFixedMemory<T>)
Represents a function that operates on a read-only fixed memory instance.
TResult ReadOnlyFixedFunc<in TArg, out TResult>(in IReadOnlyFixedMemory<T>, TArg)
Represents a function that operates on a read-only fixed memory instance using an additional state object.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that operate on fixed memory blocks of a specific type.
void FixedContextAction<T>(in IFixedContext<T>)
Encapsulates a method that receives an instance of IFixedContext<T>
.
void FixedContextAction<T, in TArg,>(in IFixedContext<T>, TArg)
Encapsulates a method that receives an instance of IFixedContext<T>
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
void ReadOnlyFixedContextAction<T>(in IReadOnlyFixedContext<T>)
Encapsulates a method that receives an instance of IReadOnlyFixedContext<T>
.
void ReadOnlyFixedContextAction<T, in TArg,>(in IFixedContext<T>, TArg)
Encapsulates a method that receives an instance of IReadOnlyFixedContext<T>
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult FixedContextFunc<T, out TResult>(in IFixedContext<T>)
Encapsulates a method that receives an instance of IFixedContext<T>
and returns a value of type TResult
.
TResult FixedContextFunc<T, in TArg, out TResult>(in IFixedContext<T>, TArg)
Encapsulates a method that receives an instance of IFixedContext<T>
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult ReadOnlyFixedContextFunc<T, out TResult>(in IReadOnlyFixedContext<T>)
Encapsulates a method that receives an instance of IReadOnlyFixedContext<T>
and returns a value of type TResult
.
TResult FixedContextFunc<T, in TArg, out TResult>(in IReadOnlyFixedContext<T>, TArg)
Encapsulates a method that receives an instance of IReadOnlyFixedContext<T>
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that operate on fixed memory references of a specific type.
void FixedReferenceAction<T>(in IFixedReference<T>)
Encapsulates a method that receives an instance of IFixedReference<T>
.
void FixedReferenceAction<T, in TArg,>(in IFixedReference<T>, TArg)
Encapsulates a method that receives an instance of IFixedReference<T>
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
void ReadOnlyFixedReferenceAction<T>(in IReadOnlyFixedReference<T>)
Encapsulates a method that receives an instance of IReadOnlyFixedReference<T>
.
void ReadOnlyFixedReferenceAction<T, in TArg,>(in IFixedReference<T>, TArg)
Encapsulates a method that receives an instance of IReadOnlyFixedReference<T>
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult FixedReferenceFunc<T, out TResult>(in IFixedReference<T>)
Encapsulates a method that receives an instance of IFixedReference<T>
and returns a value of type TResult
.
TResult FixedReferenceFunc<T, in TArg, out TResult>(in IFixedReference<T>, TArg)
Encapsulates a method that receives an instance of IFixedReference<T>
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult ReadOnlyFixedReferenceFunc<T, out TResult>(in IReadOnlyFixedReference<T>)
Encapsulates a method that receives an instance of IReadOnlyFixedReference<T>
and returns a value of type TResult
.
TResult FixedReferenceFunc<T, in TArg, out TResult>(in IReadOnlyFixedReference<T>, TArg)
Encapsulates a method that receives an instance of IReadOnlyFixedReference<T>
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that operate on methods with a fixed memory address.
void FixedMethodAction<T>(in IFixedMethod<T>)
Encapsulates a method that receives an instance of IFixedMethod<T>
.
void FixedMethodAction<T, in TArg,>(in IFixedMethod<T>, TArg)
Encapsulates a method that receives an instance of IFixedMethod<T>
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult FixedMethodFunc<T, out TResult>(in IFixedMethod<T>)
Encapsulates a method that receives an instance of IFixedMethod<T>
and returns a value of type TResult
.
TResult FixedMethodFunc<T, in TArg, out TResult>(in IFixedMethod<T>, TArg)
Encapsulates a method that receives an instance of IFixedMethod<T>
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that operate on a list of fixed memory blocks.
void FixedListAction(FixedMemoryList)
Encapsulates a method that receives an instance of FixedMemoryList
.
void FixedListAction<in TArg,>(FixedMemoryList, TArg)
Encapsulates a method that receives an instance of FixedMemoryList
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
void ReadOnlyFixedListAction(ReadOnlyFixedMemoryList)
Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList
.
void ReadOnlyFixedListAction<in TArg,>(FixedMemoryList, TArg)
Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult FixedListFunc<out TResult>(FixedMemoryList)
Encapsulates a method that receives an instance of FixedMemoryList
and returns a value of type TResult
.
TResult FixedListFunc<in TArg, out TResult>(FixedMemoryList, TArg)
Encapsulates a method that receives an instance of FixedMemoryList
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult ReadOnlyFixedListFunc<out TResult>(ReadOnlyFixedMemoryList)
Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList
and returns a value of type TResult
.
TResult FixedListFunc<in TArg, out TResult>(ReadOnlyFixedMemoryList, TArg)
Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList
and returns a value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that allow creating and operating with UTF-8/ASCII text.
void CStringSequenceCreationAction<in TArg>(Span<Byte>, Int32, TArg)
Encapsulates a method that receives a span of bytes, an index and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
void CStringSequenceAction(FixedCStringSequence)
Encapsulates a method that operates on a FixedCStringSequence
instance.
Note: In .NET 9.0+ TState
allows ref struct
.
void CStringSequenceAction<in TArg>(FixedCStringSequence, TArg)
Encapsulates a method that operates on a FixedCStringSequence
instance and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult CStringSequenceFunc<out TResult>(FixedCStringSequence)
Encapsulates a method that operates on a FixedCStringSequence
instance and returns a value of type TResult
.
TResult CStringSequenceFunc<in TArg, out TResult>(FixedCStringSequence, TArg)
Encapsulates a method that operates on a FixedCStringSequence
instance, a state object of type TArg
and returns a
value of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
These delegates encapsulate methods that operate on instances of managed buffers.
void ScopedBufferAction<T>(ScopedBuffer)
Encapsulates a method that receives a buffer of objects of type T
.
Note: In .NET 9.0+ TState
allows ref struct
.
void ScopedBufferAction<T, in TArg>(ScopedBuffer, TArg)
Encapsulates a method that receives a buffer of objects of type T
and a state object of type TArg
.
Note: In .NET 9.0+ TState
allows ref struct
.
TResult ScopedBufferFunc<T, out TResult>(ScopedBuffer)
Encapsulates a function that receives a buffer of objects of type T
and returns a result of type TResult
.
TResult ScopedBufferFunc<T, in TArg, out TResult>(ScopedBuffer, TArg)
Encapsulates a method that receives a buffer of objects of type T
, a state object of type TArg
and returns a value
of type TResult
.
Note: In .NET 9.0+ TState
allows ref struct
.
Rxmxnx.PInvoke.Extensions
provides value types for the managed handling of references, fixed memory segments, and
stack-allocated buffers
These structures safely represent memory addresses for references or methods of a specific type.
ReadOnlyValPtr<T>
Represents a platform-specific type used to manage a pointer to a read-only value of type T
.
Note: This struct implements IComparable
, ISpanFormattable
, ISerializable
, IWrapper<IntPtr>
,
IEquatable<ReadOnlyValPtr<T>>
and IComparable<ReadOnlyValPtr<T>>
interfaces.
-
Zero
A read-only field that represents a pointer that has been initialized to zero. -
IsUnmanaged
Indicates if
T
type is anunmanaged
type.
-
Pointer
Internal pointer as an
IntPtr
. -
IsZero
Indicates whether the current pointer is
null
. -
Reference
A read-only reference to the value pointed to by this instance.
-
GetUnsafeFixedReference(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedReference<T>.IDisposable
instance from current read-only reference pointer. -
GetUnsafeFixedContext(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedContext<T>.IDisposable
instance from current read-only reference pointer.
ValPtr<T>
Represents a platform-specific type used to manage a pointer to a mutable value of type T
.
Note: This struct implements IComparable
, ISpanFormattable
, ISerializable
, IWrapper<IntPtr>
,
IEquatable<ValPtr<T>>
and IComparable<ValPtr<T>>
interfaces.
-
Zero
A read-only field that represents a pointer that has been initialized to zero. -
IsUnmanaged
Indicates if
T
type is anunmanaged
type.
-
Pointer
Internal pointer as an
IntPtr
. -
IsZero
Indicates whether the current pointer is `null`. -
Reference
A reference to the value pointed to by this instance.
-
GetUnsafeFixedReference(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedReference<T>.IDisposable
instance from current reference pointer. -
GetUnsafeFixedContext(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedContext<T>.IDisposable
instance from current reference pointer.
FuncPtr<TDelegate>
Represents a platform-specific type used to handle a pointer to a method of type .
Note: This struct implements ISpanFormattable
, ISerializable
, IWrapper<IntPtr>
and IEquatable<FuncPtr<T>>
interfaces.
-
Zero
A read-only field representing a null-initialized function pointer.
-
Pointer
Internal pointer as an
IntPtr
. -
IsZero
Indicates whether the current pointer is `null`. -
Invoke
A managed delegate using the method address pointed to by this instance.
These structures represent lists of fixed memory block addresses.
ReadOnlyFixedMemoryList
Represents a list of IReadOnlyFixedMemory
instances.
Note: This type is a ref struct
. Instances of current type can be used with foreach
.
-
Count
Gets the total number of elements in the list. -
IsEmpty
Indicates whether the current list is empty.
-
Item
Gets the
IReadOnlyFixedMemory
at the specified index.
-
ToArray()
Creates an array from the current
ReadOnlyFixedMemoryList
instance.
FixedMemoryList
Represents a list of IFixedMemory
instances.
Note: This type is a ref struct
. Instances of current type can be used with foreach
.
-
Count
Gets the total number of elements in the list. -
IsEmpty
Indicates whether the current list is empty.
-
Item
Gets the
IFixedMemory
at the specified index.
-
ToArray()
Creates an array from the current
FixedMemoryList
instance.
FixedCStringSequence
Represents a CStringSequence
that is fixed in memory.
Note: This type is a ref struct
. Instances of current type can be used with foreach
.
-
Values
Gets the list of
CString
values in the sequence.
-
Item
Gets the element at the given index in the sequence.
-
ToArray()
Creates an array of
IReadOnlyFixedMemory
instances from the current instance.
These structures represent managed buffers that can be stored on the stack.
Atomic<T>
Atomic binary buffer.
Note: This type represents the binary unit 20 space.
Composite<TBufferA, TBufferB,T>
Composite binary buffer.
Notes:
- This type represents a composite binary buffer of size A + B.
TBufferA
andTBufferB
must be binary buffers.TBufferB
must always be a space of 2n.TBufferA
must be a buffer smaller than or equal toTBufferB
.- If
TBufferA
andTBufferB
are equal, the current type will represent a binary space of 2n + 1.
NonBinarySpace<TArray, T>
Non-binary buffer space.
Notes:
- This type represents a non-binary buffer based on a custom structure
TArray
. TArray
andT
must be compatible.- The size of this space is the amount of elements of type
T
can be stored in aTArray
instance.
Rxmxnx.PInvoke.Extensions
provides reference types for the managed handling of UTF8/ASCII texts, memory regions, and
metadata for stack-allocated buffer management.
ValueRegion<T>
This class represents a region of memory that contains a sequence of T
values.
Note: T
must be unmanaged
. This type not allow public inheritance.
-
IsMemorySlice
Indicates whether the current instance represents a subregion of a memory region.
-
Item
Retrieves an item from the memory region at the specified zero-based index.
-
ToArray()
Copies the contents of this memory region into a new array.
-
ReadOnlySpan<T>(ValueRegion<T>)
Converts the value of the current
ValueRegion<T>
to its equivalent read-only span representation. -
T[]?(ValueRegion<T>)
Converts the value of the current
ValueRegion<T>
to its equivalent array representation.
-
Create(T[])
Creates a new
ValueRegion<T>
instance from an array ofT
values. -
Create(IntPtr, Int32)
Creates a new
ValueRegion<T>
instance from a pointer to a native memory region. -
Create(ReadOnlySpanFunc<T>)
Creates a new
ValueRegion<T>
instance from aReadOnlySpanFunc<T>
function. -
Create<TState>(TState, ReadOnlySpanFunc<T, TState>)
Creates a new
ValueRegion<T>
instance from aReadOnlySpanFunc<T, TState>
function and TState instance.
BufferTypeMetadata
Represents the metadata of a managed buffer type.
Note: Implements IEnumerableSequence<BufferTypeMetadata>
. This type not allow public inheritance.
-
IsBinary
Indicates whether current type is binary space. -
Size
Buffer capacity. -
IsBinary
Number of components. -
BufferType
Buffer type.
-
Item
Retrieves a component from current metadata at the specified zero-based index.
BufferTypeMetadata<T>
representing a generic BufferTypeMetadata
object.
Note: Inherits from BufferTypeMetadata
. This type not allow public inheritance.
CString
Represents a sequence of UTF-8 encoded characters.
Notes:
- Implements
ICloneable
,IComparable
,IComparable<CString>
,IComparable<String>
,IEquatable<CString>
,IEquatable<String>
andIEnumerableSequence<Byte>
. - This type is sealed.
- Instances of this type can be fixed but not pinned.
- Instances of this type can be iterated using both
IEnumerable<Byte>
andReadOnlySpan<Byte>.Enumerator
. - Range operations can be used on instances of this type.
- This type exposes APIs to Join, Concat and Compare
CString
instances. - This type exposes operators of comparison and equality of
CString
andString
instances. - In .NET 9.0+
params
is used withReadOnlySpan<>
arguments instead of[]
arguments.
-
Empty
Represents an empty UTF-8 string. This field is read-only. -
Zero
Represents a null-pointer UTF-8 string. This field is read-only.
-
IsNullTerminated
Gets a value indicating whether the text in the current
CString
instance ends with a null-termination character. -
IsReference
Gets a value indicating whether the UTF-8 text is referenced by, and not contained within, the current
CString
instance. -
IsSegmented
Gets a value indicating whether the current
CString
instance is a segment (or slice) of anotherCString
instance. -
IsFunction
Gets a value indicating whether the current
CString
instance is a function.
-
Item
Gets the
Byte
value at a specified position in the currentCString
object.
-
CString(Byte, Int32)
Initializes a new instance of the
CString
class to the value indicated by a specified UTF-8 character repeated a specified number of times. -
CString(Byte, Byte, Int32)
Initializes a new instance of the
CString
class to the value indicated by a specified UTF-8 sequence repeated a specified number of times. -
CString(Byte, Byte, Byte, Int32)
Initializes a new instance of the
CString
class to the value indicated by a specified UTF-8 sequence repeated a specified number of times. -
CString(Byte, Byte, Byte, Byte, Int32)
Initializes a new instance of the
CString
class to the value indicated by a specified UTF-8 sequence repeated a specified number of times. -
CString(ReadOnlySpan<Byte>)
Initializes a new instance of the
CString
class using the UTF-8 characters indicated in the specified read-only span. -
CString(ReadOnlySpanFunc<Byte>)
Initializes a new instance of the
CString
class that contains the UTF-8 string returned by the specifiedReadOnlySpanFunc<Byte>
.
-
ToArray()
Copies the UTF-8 text of the current
CString
instance into a new byte array. -
AsSpan()
Retrieves the UTF-8 units of the current
CString
as a read-only span of bytes. -
ToHexString()
Returns a
String
that represents the current UTF-8 text as a hexadecimal value.
-
CString?(Byte[]?)
Defines an implicit conversion of a given
Byte
array toCString
. -
CString?(String?)
Defines an explicit conversion of a given
String
toCString
. -
ReadOnlySpan<Byte>(CString?)
Defines an implicit conversion of a given
CString
to a read-only span of bytes.
-
IsNullOrEmpty(CString?)
Determines whether the specified
CString
isnull
or an empty UTF-8 string. -
Create(ReadOnlySpan<Byte>)
Creates a new instance of the
CString
class using the UTF-8 characters provided in the specified read-only span. -
Create(ReadOnlySpanFunc<Byte>?)
Creates a new instance of the
CString
class using theReadOnlySpanFunc<Byte>
delegate provided. -
Create(Byte[]?)
Creates a new instance of the
CString
class using the binary internal information provided. -
CreateCreate<TState>(TState)
Creates a new instance of the
CString
class using aTState
instance. -
CreateUnsafe(IntPtr, Int32, useFullLength)
Creates a new instance of the
CString
class using the pointer to a UTF-8 character array and length provided.
CStringSequence
Represents a sequence of null-terminated UTF-8 text strings.
Notes:
- Implements
ICloneable
,IEquatable<CString>
,IComparable<CStringSequence>
,IReadOnlyList<CString>
andIEnumerableSequence<CString>
. - This type is sealed.
- The instances of this type can be fixed but not pinned.
- Range operations can be used on instances of this type.
- This type exposes constructors to create sequences from up to 8 instances of
ReadOnlySpan<Byte>
in order to optimize memory usage. - In .NET 9.0+
params
is used withReadOnlySpan<>
arguments instead of[]
arguments.
-
Empty
Represents an empty sequence.
-
Count
Gets the number of
CString
instances contained in thisCStringSequence
.
-
Item
Gets the
CString
at the specified index.
-
CStringSequence(params String?[])
Initializes a new instance of the
CStringSequence
class from a collection of strings. -
CStringSequence(params CString?[])
Initializes a new instance of the
CStringSequence
class from a collection of UTF-8 strings. -
CStringSequence(ReadOnlySpan<CString>)
Initializes a new instance of the
CStringSequence
class from a read-only span of UTF-8 strings. -
CStringSequence(ReadOnlySpan<String>)
Initializes a new instance of the
CStringSequence
class from a read-only span of strings. -
CStringSequence(IReadOnlySpan<String?>)
Initializes a new instance of the
CStringSequence
class from a collection of strings. -
CStringSequence(IReadOnlySpan<CString?>)
Initializes a new instance of the
CStringSequence
class from a collection of UTF-8 strings.
-
ToCString()
Returns a
CString
that represents the current sequence. -
GetFixedPointer()
Creates an
IFixedPointer.IDisposable
instance by pinning the current instance, allowing safe access to the fixed memory region. -
WithSafeTransform(CStringSequenceAction)
Executes a specified action using the current instance treated as a
FixedCStringSequence
. -
WithSafeTransform<TState>(TState, CStringSequenceAction)
Executes a specified action on the current instance treated as a
FixedCStringSequence
, using an additional parameter passed to the action. -
WithSafeTransform<TResult>(CStringSequenceFunc<TResult>)
Executes a specified function using the current instance treated as a
FixedCStringSequence
. -
WithSafeTransform<TState, TResult>(TState, CStringSequenceFunc<TResult>)
Executes a specified function using the current instance treated as a
FixedCStringSequence
, and an additional parameter passed to the function.
-
CString?(Byte[]?)
Defines an implicit conversion of a given
Byte
array toCString
. -
CString?(String?)
Defines an explicit conversion of a given
String
toCString
. -
ReadOnlySpan<Byte>(CString?)
Defines an implicit conversion of a given
CString
to a read-only span of bytes. -
ReadOnlySpan<Byte>(CString?)
Defines an implicit conversion of a given
CString
to a read-only span of bytes.
-
Create<TState>(TState, CStringSequenceCreationAction<TState>, params Int32?[])
Creates a new UTF-8 text sequence with specific lengths, and initializes each UTF-8 text string in it after creation using the specified callback. -
Create(ReadOnlySpan<Char>)
Creates a new
CStringSequence
instance from a UTF-8 buffer. -
Parse(String?)
Converts the buffer of a UTF-8 sequence to a
CStringSequence
instance.
Rxmxnx.PInvoke.Extensions
provides static classes that expose APIs to facilitate the management of managed memory,
pointer usage, and this package's internal resources.
BinaryExtensions
Set of useful methods when working with bytes, byte arrays, and byte spans in a PInvoke context.
-
ToValue<T>(this Byte[])
Retrieves a
T
value from the given byte array.Note: ´T´ is ´unmanaged´.
-
ToValue<T>(this Span<Byte>)
Retrieves a
T
value from the given byte span.Note: ´T´ is ´unmanaged´.
-
ToValue<T>(this ReadOnlySpan<Byte>)
Retrieves a
T
value from the given read-only byte span.Note: ´T´ is ´unmanaged´.
-
AsValue<T>(this ReadOnlySpan<Byte>)
Retrieves a read-only reference to a
T
value from the given read-only byte span.Note: ´T´ is ´unmanaged´.
-
AsValue<T>(this Span<Byte>)
Retrieves a reference to a
T
value from the given byte span.Note: ´T´ is ´unmanaged´.
-
AsHexString(this Byte[])
Gets the hexadecimal string representation of a byte array. -
AsHexString(this Byte)
Gets the hexadecimal string representation of a byte. -
WithSafeFixed(this Span<Byte>, FixedAction)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed(this Span<Byte>, ReadOnlyFixedAction)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed(this ReadOnlySpan<Byte>, ReadOnlyFixedAction)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed. -
WithSafeFixed<TArg>(this Span<Byte>, FixedAction<TArg>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed<TArg>(this Span<Byte>, ReadOnlyFixedAction<TArg>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed<TArg>(this ReadOnlySpan<Byte>, ReadOnlyFixedAction<TArg>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed. -
WithSafeFixed<TResult>(this Span<Byte>, FixedFunc<TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<TResult>(this Span<Byte>, ReadOnlyFixedFunc<TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<TResult>(this ReadOnlySpan<Byte>, ReadOnlyFixedFunc<TResult>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed. -
WithSafeFixed<TArg, TResult>(this Span<Byte>, TArg, FixedFunc<TArg, TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<TArg, TResult>(this Span<Byte>, TArg, ReadOnlyFixedFunc<TArg, TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<TArg, TResult>(this ReadOnlySpan<Byte>, TArg, ReadOnlyFixedFunc<TArg, TResult>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed.
DelegateExtensions
Additional functionality for working with delegates.
-
GetUnsafeFuncPtr<TDelegate>(this TDelegate)
Creates a
FuncPtr<TDelegate>
from a memory reference to aTDelegate
delegate instance. -
GetUnsafeIntPtr<TDelegate>(this TDelegate)
Retrieves an
IntPtr
from a memory reference to aTDelegate
delegate instance. -
GetUnsafeUIntPtr<TDelegate>(this TDelegate)
Retrieves a
UIntPtr
from a memory reference to aTDelegate
delegate instance. -
WithSafeFixed<TDelegate>(this TDelegate, FixedMethodAction<TDelegate>)
Prevents the garbage collector from relocating a delegate in memory and fixes its address while an action is being performed. -
WithSafeFixed<TDelegate, TArg>(this TDelegate, TArg, FixedMethodAction<TDelegate, TArg>)
Prevents the garbage collector from relocating a delegate in memory and fixes its address while an action is being performed, passing an additional argument to the action. -
WithSafeFixed<TDelegate, TResult>(this TDelegate, TArg, FixedMethodFunc<TDelegate, TResult>)
Prevents the garbage collector from relocating a delegate in memory, fixes its address, and invokes the function that returns a
TResult
value. -
WithSafeFixed<TDelegate, TArg, TResult>(this TDelegate, TArg, FixedMethodFunc<TDelegate, TArg, TResult>)
Prevents the garbage collector from relocating a delegate in memory, fixes its address, invokes the function that returns a
TResult
value, passing an additional argument to the function.
MemoryBlockExtensions
Additional functionality for working with memory blocks.
-
GetUnsafeValPtr<T>(this Span<T>)
Retrieves an unsafe
ValPtr<T>
pointer fromSpan<T>
instance. -
GetUnsafeValPtr<T>(this ReadOnlySpan<T>)
Retrieves an unsafe
ValPtr<T>
pointer fromReadOnlySpan<T>
instance. -
GetUnsafePtr<T>(this Span<T>)
Retrieves an unsafe
IntPtr
pointer fromSpan<TZ
instance. -
GetUnsafePtr<T>(this ReadOnlySpan<T>)
Retrieves an unsafe
IntPtr
pointer fromReadOnlySpan<T>
instance. -
GetUnsafeUIntPtr<T>(this Span<T>)
Retrieves an unsafe
UIntPtr
pointer fromSpan<T>
instance. -
GetUnsafeUIntPtr<T>(this ReadOnlySpan<T>)
Retrieves an unsafe
UIntPtr
pointer fromReadOnlySpan<T>
instance. -
AsBytes<TSource>(this Span<TSource>)
Reinterprets the span of
TSource
as a binary span.Note:
TSource
isunmanaged
. -
AsBytes<TSource>(this ReadOnlySpan<TSource>)
Reinterprets the read-only span of
TSource
as a read-only binary span.Note:
TSource
isunmanaged
. -
AsValues<TSource, TDestination>(this Span<TSource>)
Reinterprets the span of
TSource
as a span ofTDestination
.Note:
TSource
isunmanaged
.TDestination
isunmanaged
. -
AsValues<TSource, TDestination>(this ReadOnlySpan<TSource>)
Reinterprets the read-only span of
TSource
as a read-only span ofTDestination
.Note:
TSource
isunmanaged
.TDestination
isunmanaged
. -
AsValues<TSource, TDestination>(this Span<TSource>, Span<Byte>)
Reinterprets the span of
TSource
as a span ofTDestination
.Note:
TSource
isunmanaged
.TDestination
isunmanaged
. -
AsValues<TSource, TDestination>(this Span<TSource>, ReadOnlySpan<Byte>)
Reinterprets the span of
TSource
as a read-only span ofTDestination
.Note:
TSource
isunmanaged
.TDestination
isunmanaged
. -
AsValues<TSource, TDestination>(this ReadOnlySpan<TSource>, ReadOnlySpan<Byte>)
Reinterprets the read-only span of
TSource
as a read-only span ofTDestination
.Note:
TSource
isunmanaged
.TDestination
isunmanaged
. -
GetFixedContext<T>(this ReadOnlyMemory<T>)
Creates an
IReadOnlyFixedContext<T>.IDisposable
instance by pinning the currentReadOnlyMemory<T>
instance, ensuring a safe context for accessing the fixed memory.Note:
T
isunmanaged
. -
GetFixedContext<T>(this Memory<T>)
Creates an
IFixedContext<T>.IDisposable
instance by pinning the currentMemory<T>
instance, ensuring a safe context for accessing the fixed memory.Note:
T
isunmanaged
. -
GetFixedMemory<T>(this ReadOnlyMemory<T>)
Creates an
IReadOnlyFixedMemory<T>.IDisposable
instance by pinning the currentReadOnlyMemory<T>
instance, ensuring a safe context for accessing the fixed memory.Note:
T
isunmanaged
. -
GetFixedMemory<T>(this Memory<T>)
Creates an
IFixedMemory<T>.IDisposable
instance by pinning the currentMemory<T>
instance, ensuring a safe context for accessing the fixed memory.Note:
T
isunmanaged
. -
AsMemory<T>(this T[...])
Creates a new memory region over the target array. -
AsSpan<T>(this T[...])
Creates a new span over a target array. -
WithSafeFixed<T>(this Span<T>, FixedContextAction<T>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed<T>(this Span<T>, ReadOnlyFixedContextAction<T>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed<T>(this ReadOnlySpan<T>, ReadOnlyFixedContextAction<T>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed. -
WithSafeFixed<T, TArg>(this Span<T>, FixedContextAction<T, TArg>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed<T, TArg>(this Span<T>, ReadOnlyFixedContextAction<T, TArg>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed. -
WithSafeFixed<T, TArg>(this ReadOnlySpan<T>, ReadOnlyFixedContextAction<T, TArg>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed. -
WithSafeFixed<T, TResult>(this Span<T>, FixedContextFunc<T, TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<T, TResult>(this Span<T>, ReadOnlyFixedContextFunc<T, TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<T, TResult>(this ReadOnlySpan<T>, ReadOnlyFixedContextFunc<T, TResult>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed. -
WithSafeFixed<T, TArg, TResult>(this Span<T>, TArg, FixedContextFunc<T, TArg, TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<T, TArg, TResult>(this Span<T>, TArg, ReadOnlyFixedContextFunc<T, TArg, TResult>)
Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed. -
WithSafeFixed<T, TArg, TResult>(this ReadOnlySpan<T>, TArg, ReadOnlyFixedContextFunc<T, TArg, TResult>)
Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed.
PointerExtensions
Set of extensions for basic operations with IntPtr
and UIntPtr
instances.
-
IsZero(this IntPtr)
Determines if the
IntPtr
instance is zero. -
IsZero(this UIntPtr)
Determines if the
UIntPtr
instance is zero. -
ToUIntPtr(this IntPtr)
Converts the specified
IntPtr
instance to aUIntPtr
instance. -
ToUIntPtr(this MemoryHandle)
Converts the specified `MemoryHandle` instance to a `UIntPtr` instance. -
ToIntPtr(this UIntPtr)
Converts the specified
UIntPtr
instance to aIntPtr
instance. -
ToIntPtr(this MemoryHandle)
Converts the specified
MemoryHandle
instance to aIntPtr
instance. -
GetUnsafeString(this IntPtr)
Generates a
String
instance from the memory at the givenIntPtr
, interpreting the contents as UTF-16 text. -
GetUnsafeString(this UIntPtr)
Generates a
String
instance from the memory at the givenUIntPtr
, interpreting the contents as UTF-16 text. -
GetUnsafeString(this MemoryHandle)
Generates a
String
instance from the memory at the givenMemoryHandle
, interpreting the contents as UTF-16 text. -
GetUnsafeString(this IntPtr, Int32)
Generates a
String
instance from the memory at the givenIntPtr
, interpreting the contents as UTF-16 text. -
GetUnsafeString(this UIntPtr, Int32)
Generates a
String
instance from the memory at the givenUIntPtr
, interpreting the contents as UTF-16 text. -
GetUnsafeString(this MemoryHandle, Int32)
Generates a
String
instance from the memory at the givenMemoryHandle
, interpreting the contents as UTF-16 text. -
GetUnsafeArray<T>(this IntPtr, Int32)
Generates a
T
array by copying values from memory starting at the location referenced by anIntPtr
.Note: ´T´ is ´unmanaged´.
-
GetUnsafeArray<T>(this UIntPtr, Int32)
Generates a
T
array by copying values from memory starting at the location referenced by aUIntPtr
.Note: ´T´ is ´unmanaged´.
-
GetUnsafeArray<T>(this MemoryHandle, Int32)
Generates a
T
array by copying values from memory starting at the location referenced by aMemoryHandle
.Note: ´T´ is ´unmanaged´.
-
GetUnsafeSpan<T>(this IntPtr, Int32)
Generates a
Span<T>
instance from anIntPtr
, interpreting the memory at the specified location as a sequence ofunmanaged
values.Note: ´T´ is ´unmanaged´.
-
GetUnsafeSpan<T>(this UIntPtr, Int32)
Generates a
Span<T>
instance from aUIntPtr
, interpreting the memory at the specified location as a sequence ofunmanaged
values.Note: ´T´ is ´unmanaged´.
-
GetUnsafeSpan<T>(this MemoryHandle, Int32)
Generates a
Span<T>
instance from aMemoryHandle
, interpreting the memory at the specified location as a sequence ofunmanaged
values.Note: ´T´ is ´unmanaged´.
-
GetUnsafeReadOnlySpan<T>(this IntPtr, Int32)
Generates a
ReadOnlySpan<T>
instance from anIntPtr
, interpreting the memory at the specified location as a sequence ofunmanaged
values.Note: ´T´ is ´unmanaged´.
-
GetUnsafeReadOnlySpan<T>(this UIntPtr, Int32)
Generates a
ReadOnlySpan<T>
instance from aUIntPtr
, interpreting the memory at the specified location as a sequence ofunmanaged
values.Note: ´T´ is ´unmanaged´.
-
GetUnsafeReadOnlySpan<T>(this MemoryHandle, Int32)
Generates a
ReadOnlySpan<T>
instance from aMemoryHandle
, interpreting the memory at the specified location as a sequence ofunmanaged
values.Note: ´T´ is ´unmanaged´.
-
GetUnsafeDelegate<TDelegate>(this IntPtr)
Generates a delegate of type
TDelegate
from anIntPtr
. -
GetUnsafeDelegate<TDelegate>(this UIntPtr)
Creates a delegate of type
TDelegate
from aUIntPtr
. -
GetUnsafeReference<T>(this IntPtr)
Generates a memory reference to an
unmanaged
value of typeT
fromIntPtr
. -
GetUnsafeReference<T>(this UIntPtr)
Generates a memory reference to an
unmanaged
value of typeT
fromUIntPtr
. -
GetUnsafeReadOnlyReference<T>(this IntPtr)
Generates a read-only memory reference to an
unmanaged
value of typeT
fromIntPtr
. -
GetUnsafeReadOnlyReference<T>(this UIntPtr)
Generates a read-only memory reference to an
unmanaged
value of typeT
fromUIntPtr
.
PointerCStringExtensions
Set of extensions for CString
operations with IntPtr
and UIntPtr
instances.
-
GetUnsafeCString(this IntPtr, Int32)
Generates a
CString
instance using the memory reference pointed to by the givenIntPtr
, considering it as the start of a UTF-8 encoded string. -
GetUnsafeCString(this UIntPtr, Int32)
Generates a
CString
instance using the memory reference pointed to by the givenUIntPtr
, considering it as the start of a UTF-8 encoded string. -
GetUnsafeCString(this MemoryHandle, Int32)
Generates a
CString
instance using the memory reference pointed to by the givenMemoryHandle
, considering it as the start of a UTF-8 encoded string.
ReferenceExtensions
Set of extensions for basic operations with references to unmanaged
values.
-
GetUnsafeValPtr<T>(ref this T)
Obtains an unsafe pointer of type
ValPtr<T>
from a reference to anunmanaged
value of typeT
. -
GetUnsafeIntPtr<T>(ref this T)
Obtains an unsafe pointer of type
IntPtr
from a reference to anunmanaged
value of typeT
. -
GetUnsafeUIntPtr<T>(ref this T)
Obtains an unsafe pointer of type
UIntPtr
from a reference to anunmanaged
value of typeT
. -
Transform<TSource, TDestination>(ref this TSource)
Generates a reference for an
unmanaged
value of typeTDestination
from an existing reference to anunmanaged
value of typeTSource
. -
AsBytes<TSource>(ref this TSource)
Creates a
Span<Byte>
from a reference to anunmanaged
value of typeTSource
. -
WithSafeFixed<T>(ref this T, FixedReferenceAction<T>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action. -
WithSafeFixed<T>(ref this T, ReadOnlyFixedReferenceAction<T>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action. -
WithSafeFixed<T, TArg>(ref this T, TArg, FixedReferenceAction<T, TArg>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action along with an argument. -
WithSafeFixed<T, TArg>(ref this T, TArg, ReadOnlyFixedReferenceAction<T, TArg>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action along with an argument. -
WithSafeFixed<T, TResult>(ref this T, FixedReferenceFunc<T, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function. -
WithSafeFixed<T, TResult>(ref this T, ReadOnlyFixedReferenceFunc<T, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function. -
WithSafeFixed<T, TArg, TResult>(ref this T, TArg, FixedReferenceFunc<T, TArg, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function along with an argument. -
WithSafeFixed<T, TArg, TResult>(ref this T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function along with an argument.
StringExtensions
Set of extensions for basic operations with String
instances.
-
WithSafeFixed(this String?, ReadOnlyFixedContextAction<Char>)
Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified action. -
WithSafeFixed<TArg>(this String?, TArg, ReadOnlyFixedContextAction<Char, TArg>)
Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified action along with an argument. -
WithSafeFixed<TResult>(this String?, ReadOnlyFixedContextFunc<Char, TResult>)
Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified function. -
WithSafeFixed<TArg, TResult>(this String?, TArg, ReadOnlyFixedContextFunc<Char, TArg, TResult>)
Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified function along with an argument.
UnmanagedValueExtensions
Set of extensions for basic operations with unmanaged
values.
-
ToBytes<T>(this T)
Converts a given
unmanaged
value of typeT
into an array ofByte
. -
ToBytes<TSource>(this TSource[]?)
Converts an array of
unmanaged
values of typeTSource
into an array ofByte
. -
ToValues<TSource, TDestination>(this TSource[]?)
Converts an array of
unmanaged
values of typeTSource
into an array of anotherunmanaged
value typeTDestination
. -
ToValues<TSource, TDestination>(this TSource[]?, out Byte[]?)
Converts an array of
unmanaged
values of typeTSource
into an array of anotherunmanaged
value typeTDestination
and provides the residual binary array of the reinterpretation. -
WithSafeFixed<T>(ref this T, FixedReferenceAction<T>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action. -
WithSafeFixed<T>(ref this T, ReadOnlyFixedReferenceAction<T>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action. -
WithSafeFixed<T, TArg>(ref this T, TArg, FixedReferenceAction<T, TArg>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action along with an argument. -
WithSafeFixed<T, TArg>(ref this T, TArg, ReadOnlyFixedReferenceAction<T, TArg>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action along with an argument. -
WithSafeFixed<T, TResult>(ref this T, FixedReferenceFunc<T, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function. -
WithSafeFixed<T, TResult>(ref this T, ReadOnlyFixedReferenceFunc<T, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function. -
WithSafeFixed<T, TArg, TResult>(ref this T, TArg, FixedReferenceFunc<T, TArg, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function along with an argument. -
WithSafeFixed<T, TArg, TResult>(ref this T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>)
Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function along with an argument.
Rxmxnx.PInvoke.Extensions
provides static classes that complement the APIs facilitating the management of read-only
managed memory, enable interaction with the runtime environment, and allow the use of the package's internal resources.
AotInfo
Provides information about the Ahead-of-Time compilation.
-
IsReflectionDisabled
Indicates whether runtime reflection is disabled. -
IsNativeAot
Indicates whether the current runtime is NativeAOT.
BufferManager
This class allows to allocate buffers on stack if possible.
-
BufferAutoCompositionEnabled
Indicates whether metadata for any required buffer is auto-composed.Note: This property will always be false if compiled with
IlcDisableReflection=true
or if thePInvoke.DisableBufferAutoComposition
feature switch is enabled.
-
Alloc<T>(UInt16, ScopedBufferAction<T>, Boolean)
Allocates a buffer with
count
elements and executesaction
. -
Alloc<T, TState>(UInt16, TState, ScopedBufferAction<T, TState>, Boolean)
Allocates a buffer with
count
elements and executesaction
. -
Alloc<T, TResult>(UInt16, ScopedBufferFunc<T, TResult>, Boolean)
Allocates a buffer with
count
elements and executesfunc
. -
Alloc<T, TState, TResult>(UInt16, TState, ScopedBufferFunc<T, TState, TResult>, Boolean)
Allocates a buffer with
count
elements and executesfunc
. -
Register<TBuffer>()
Registers object buffer.Note:
TBuffer
isstruct
andIManagedBuffer<Object>
. -
Register<T, TBuffer>()
Registers
T
buffer.Note:
T
isstruct
.TBuffer
isstruct
andIManagedBuffer<T>
. -
RegisterNullable<T, TBuffer>()
Registers
T?
buffer.Note:
T
isstruct
.TBuffer
isstruct
andIManagedBuffer<T?>
.
NativeUtilities
Set of utilities for exchange data within the P/Invoke context.
-
PointerSize
Size in bytes of a memory pointer.
-
SizeOf<T>()
Gets the memory size of
T
structure.Note:
T
isunmanaged
. -
LoadNativeLib(String?, DllImportSearchPath?)
Provides a high-level API for loading a native library. -
LoadNativeLib(String?, ref EventHandler?, DllImportSearchPath?)
Provides a high-level API for loading a native library. -
GetNativeMethod<TDelegate>(IntPtr, String?)
Gets the TDelegate delegate of an exported symbol. -
GetUnsafeFuncPtr<TDelegate>(TDelegate)
Creates an
FuncPtr<TDelegate>
from a memory reference to aTDelegate
delegate instance. -
GetUnsafeValPtr<T>(in T)
Retrieves an unsafe
ReadOnlyValPtr<T>
pointer from a read-only reference to aT
value. -
GetUnsafeValPtrFromRef<T>(ref T)
Retrieves an unsafe pointer of type
ValPtr<T>
from a reference to a value of type T. -
GetUnsafeIntPtr<T>(in T)
Retrieves an unsafe
IntPtr
pointer from a read-only reference to aT
unmanaged
value. -
GetUnsafeUIntPtr<T>(in T)
Retrieves an unsafe
UIntPtr
pointer from a read-only reference to aT
unmanaged
value. -
Transform<TSource, TDestination>(in TSource)
Transforms a read-only reference of an
unmanaged
value of typeTSource
into a read-only reference of anunmanaged
value of typeTDestination
. -
TransformReference<TSource, TDestination>(ref TSource)
Transforms a reference of an
unmanaged
value of typeTSource
into a reference of anunmanaged
value of typeTDestination
. -
ToBytes<T>(in TSource)
Retrieves a
Byte
array from a read-only reference to aTSource
value.Note:
TSource
isunmanaged
. -
AsBytes<TSource>(in TSource)
Creates a
ReadOnlySpan<Byte>
from an exising read-only reference to aTSource
unmanaged
value. -
AsBinarySpan<TSource>(ref TSource)
Creates a
Span<Byte>
from an exising reference to aTSource
value.Note:
TSource
isunmanaged
. -
CreateArray<T, TState>(Int32, TState, SpanAction<T, TState>)
Creates a new
T
array with a specific length and initializes it after creation by using the specified callback.Note:
T
isunmanaged
. -
CopyBytes<T>(in TSource, Span<Byte>, Int32)
Performs a binary copy of the given
TSource
to the destination span.Note:
TSource
isunmanaged
. -
WithSafeReadOnlyFixed<T>(ref T, ReadOnlyFixedReferenceAction<T>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes. -
WithSafeReadOnlyFixed<T, TArg>(ref T, TArg, ReadOnlyFixedReferenceAction<T, TArg>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes. -
WithSafeReadOnlyFixed<T, TResult>(ref T, ReadOnlyFixedReferenceFunc<T, TResult>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes. -
WithSafeReadOnlyFixed<T, TArg, TResult>(ref T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes. -
WithSafeFixed<T>(in T, ReadOnlyFixedReferenceAction<T>)
Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until action finishes. -
WithSafeFixed<T>(ref T, FixedReferenceAction<T>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes. -
WithSafeFixed<T, TArg>(in T, TArg, ReadOnlyFixedReferenceAction<T, TArg>)
Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until action finishes. -
WithSafeFixed<T, TArg>(ref T, TArg, FixedReferenceAction<T, TArg>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes. -
WithSafeFixed<T, TResult>(in T, ReadOnlyFixedReferenceFunc<T, TResult>)
Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until func finishes. -
WithSafeFixed<T, TResult>(ref T, FixedReferenceFunc<T, TResult>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes. -
WithSafeFixed<T, TArg, TResult>(in T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>)
Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until func finishes. -
WithSafeFixed<T, TArg, TResult>(ref T, TArg, FixedReferenceFunc<T, TArg, TResult>)
Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes. -
WithSafeFixed<TDelegate>(TDelegate, FixedMethodAction<TDelegate>)
Prevents the garbage collector from relocating a given method delegate and fixes its memory address until action finishes. -
WithSafeFixed<TDelegate, TArg>(TDelegate, TArg, FixedMethodAction<TDelegate, TArg>)
Prevents the garbage collector from relocating a given method delegate and fixes its memory address until action finishes. -
WithSafeFixed<TDelegate, TResult>(TDelegate, FixedMethodFunc<TDelegate, TResult>)
Prevents the garbage collector from relocating a given method delegate and fixes its memory address until func finishes. -
WithSafeFixed<TDelegate, TArg, TResult>(TDelegate, TArg, FixedMethodFunc<TDelegate, TArg, TResult>)
Prevents the garbage collector from relocating a given method delegate and fixes its memory address until func finishes. -
WithSafeFixed<T0, ..., T7>(Span<T0>, ..., Span<T7>, FixedListAction)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes. -
WithSafeFixed<T0, ..., T7, TArg>(Span<T0>, ..., Span<T7>, TArg, FixedListAction<TArg>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes. -
WithSafeFixed<T0, ..., T7>(ReadOnlySpan<T0>, ..., ReadOnlySpan<T7>, ReadOnlyFixedListAction)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes. -
WithSafeFixed<T0, ..., T7, TArg>(ReadOnlySpan<T0>, ..., ReadOnlySpan<T7>, TArg, ReadOnlyFixedListAction<TArg>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes. -
WithSafeFixed<T0, ..., T7, TResult>(Span<T0>, ..., Span<T7>, FixedListFunc<TResult>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes. -
WithSafeFixed<T0, ..., T7, TArg, TResult>(Span<T0>, ..., Span<T7>, TArg, FixedListFunc<TArg, TResult>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes. -
WithSafeFixed<T0, ..., T7, TResult>(ReadOnlySpan<T0>, ..., ReadOnlySpan<T7>, ReadOnlyFixedListFunc<TResult>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes. -
WithSafeFixed<T0, ..., T7, TArg, TResult>(Span<T0>, ..., Span<T7>, TArg, ReadOnlyFixedListFunc<TArg, TResult>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes. -
WithSafeReadOnlyFixed<T0, ..., T7>(Span<T0>, ..., Span<T7>, ReadOnlyFixedListAction)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes. -
WithSafeReadOnlyFixed<T0, ..., T7, TArg>(Span<T0>, ..., Span<T7>, TArg, ReadOnlyFixedListAction<TArg>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes. -
WithSafeReadOnlyFixed<T0, ..., T7, TResult>(Span<T0>, ..., Span<T7>, ReadOnlyFixedListFunc<TResult>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes. -
WithSafeReadOnlyFixed<T0, ..., T7, TArg, TResult>(Span<T0>, ..., Span<T7>, TArg, ReadOnlyFixedListFunc<TArg, TResult>)
Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.
This project is licensed under the MIT License, one of the most permissive and widely-used open-source licenses.
- Freedom of Use: The package can be used in both open-source and closed-source projects without restrictions.
- Modification and Distribution: You are free to modify, distribute, and even sublicense the software as needed.
- Attribution: The only requirement is to include the original copyright notice and license text in any copies or substantial portions of the software.
The software is provided "as is," without warranty of any kind. The authors are not liable for any damages or issues that may arise from its use.
For more details, refer to the full license text included in the LICENSE file.
We warmly welcome contributions to this open-source project! Whether you're here to report issues, propose enhancements, or contribute directly to the codebase, your help is greatly appreciated. Below are some ways you can get involved:
If you encounter a bug, experience unexpected behavior, or have suggestions for improvement, feel free to open an issue. Please include as much detail as possible, such as:
- Steps to reproduce the problem
- Your environment (e.g., OS, software version)
- Any relevant logs or screenshots
Have an idea for a new feature or enhancement? Open an issue with a clear description of your proposal and why you think it would benefit the project.
You can directly contribute to the project by:
- Fixing bugs
- Adding new features
- Improving existing functionality
- Enhancing documentation
To contribute code:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and commit them with clear and concise messages.
- Submit a pull request for review.
Feel free to discuss your ideas or changes in an issue or pull request to align with the project's goals.
We currently support only a few languages, but we are open to adding more! If you'd like to help with translations, please open an issue or reach out to us. Your contributions to expanding the project's accessibility are highly valued.
When contributing, please be respectful and constructive. We aim to create an inclusive and welcoming environment for everyone.
Thank you for considering contributing to this project! Your involvement, whether through reporting, coding, or translating, helps make this project better for everyone. 🚀