IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Runtime.Extensions.MemoryMarshalExtensions Class Reference

Static Public Member Functions

static unsafe int GetIndexOfNull (byte *ptr, int max=int.MaxValue)
 Gets the length of a pointer to a C string.
 
static unsafe ReadOnlySpan< byte > CreateReadOnlySpanFromNullTerminated (byte *b)
 Creates a ReadOnlySpan<byte> from the given pointer.
 

Detailed Description

Definition at line 7 of file MemoryMarshalExtensions.cs.

Member Function Documentation

◆ CreateReadOnlySpanFromNullTerminated()

static unsafe ReadOnlySpan< byte > IKVM.Runtime.Extensions.MemoryMarshalExtensions.CreateReadOnlySpanFromNullTerminated ( byte * b)
static

Creates a ReadOnlySpan<byte> from the given pointer.

Parameters
b
Returns

Definition at line 35 of file MemoryMarshalExtensions.cs.

36 {
37#if NETFRAMEWORK
38 return new ReadOnlySpan<byte>(b, GetIndexOfNull(b));
39#else
40 return MemoryMarshal.CreateReadOnlySpanFromNullTerminated(b);
41#endif
42 }
static unsafe int GetIndexOfNull(byte *ptr, int max=int.MaxValue)
Gets the length of a pointer to a C string.

◆ GetIndexOfNull()

static unsafe int IKVM.Runtime.Extensions.MemoryMarshalExtensions.GetIndexOfNull ( byte * ptr,
int max = int::MaxValue )
static

Gets the length of a pointer to a C string.

Parameters
ptr
max
Returns

Definition at line 16 of file MemoryMarshalExtensions.cs.

17 {
18 if (ptr is null)
19 throw new ArgumentNullException(nameof(ptr));
20 if (max < 0)
21 throw new ArgumentOutOfRangeException(nameof(max));
22
23 for (int i = 0; i < max; i++)
24 if (ptr[i] == 0)
25 return i;
26
27 return -1;
28 }

The documentation for this class was generated from the following file: