System.Memory
Reads bytes as primitives with specific endianness
For native formats, MemoryExtensions.Read{T}; should be used.
Use these helpers when you need to read specific endinanness.
This is a no-op and added only for consistency.
This allows the caller to read a struct of numeric primitives and reverse each field
rather than having to skip sbyte fields.
Reverses a primitive value - performs an endianness swap
Reverses a primitive value - performs an endianness swap
Reverses a primitive value - performs an endianness swap
This is a no-op and added only for consistency.
This allows the caller to read a struct of numeric primitives and reverse each field
rather than having to skip byte fields.
Reverses a primitive value - performs an endianness swap
Reverses a primitive value - performs an endianness swap
Reverses a primitive value - performs an endianness swap
Reads an Int16 out of a read-only span of bytes as big endian.
Reads an Int32 out of a read-only span of bytes as big endian.
Reads an Int64 out of a read-only span of bytes as big endian.
Reads a UInt16 out of a read-only span of bytes as big endian.
Reads a UInt32 out of a read-only span of bytes as big endian.
Reads a UInt64 out of a read-only span of bytes as big endian.
Reads an Int16 out of a read-only span of bytes as big endian.
If the span is too small to contain an Int16, return false.
Reads an Int32 out of a read-only span of bytes as big endian.
If the span is too small to contain an Int32, return false.
Reads an Int64 out of a read-only span of bytes as big endian.
If the span is too small to contain an Int64, return false.
Reads a UInt16 out of a read-only span of bytes as big endian.
If the span is too small to contain a UInt16, return false.
Reads a UInt32 out of a read-only span of bytes as big endian.
If the span is too small to contain a UInt32, return false.
Reads a UInt64 out of a read-only span of bytes as big endian.
If the span is too small to contain a UInt64, return false.
Reads an Int16 out of a read-only span of bytes as little endian.
Reads an Int32 out of a read-only span of bytes as little endian.
Reads an Int64 out of a read-only span of bytes as little endian.
Reads a UInt16 out of a read-only span of bytes as little endian.
Reads a UInt32 out of a read-only span of bytes as little endian.
Reads a UInt64 out of a read-only span of bytes as little endian.
Reads an Int16 out of a read-only span of bytes as little endian.
If the span is too small to contain an Int16, return false.
Reads an Int32 out of a read-only span of bytes as little endian.
If the span is too small to contain an Int32, return false.
Reads an Int64 out of a read-only span of bytes as little endian.
If the span is too small to contain an Int64, return false.
Reads a UInt16 out of a read-only span of bytes as little endian.
If the span is too small to contain a UInt16, return false.
Reads a UInt32 out of a read-only span of bytes as little endian.
If the span is too small to contain a UInt32, return false.
Reads a UInt64 out of a read-only span of bytes as little endian.
If the span is too small to contain a UInt64, return false.
Writes an Int16 into a span of bytes as big endian.
Writes an Int32 into a span of bytes as big endian.
Writes an Int64 into a span of bytes as big endian.
Write a UInt16 into a span of bytes as big endian.
Write a UInt32 into a span of bytes as big endian.
Write a UInt64 into a span of bytes as big endian.
Writes an Int16 into a span of bytes as big endian.
If the span is too small to contain the value, return false.
Writes an Int32 into a span of bytes as big endian.
If the span is too small to contain the value, return false.
Writes an Int64 into a span of bytes as big endian.
If the span is too small to contain the value, return false.
Write a UInt16 into a span of bytes as big endian.
If the span is too small to contain the value, return false.
Write a UInt32 into a span of bytes as big endian.
If the span is too small to contain the value, return false.
Write a UInt64 into a span of bytes as big endian.
If the span is too small to contain the value, return false.
Writes an Int16 into a span of bytes as little endian.
Writes an Int32 into a span of bytes as little endian.
Writes an Int64 into a span of bytes as little endian.
Write a UInt16 into a span of bytes as little endian.
Write a UInt32 into a span of bytes as little endian.
Write a UInt64 into a span of bytes as little endian.
Writes an Int16 into a span of bytes as little endian.
If the span is too small to contain the value, return false.
Writes an Int32 into a span of bytes as little endian.
If the span is too small to contain the value, return false.
Writes an Int64 into a span of bytes as little endian.
If the span is too small to contain the value, return false.
Write a UInt16 into a span of bytes as little endian.
If the span is too small to contain the value, return false.
Write a UInt32 into a span of bytes as little endian.
If the span is too small to contain the value, return false.
Write a UInt64 into a span of bytes as little endian.
If the span is too small to contain the value, return false.
Extension methods for
Returns position of first occurrence of item in the
Copy the to the specified .
The source .
The destination .
Converts the to an array
Writes contents of to
Represents a sink
Notifies that amount of data was written to /
Requests the that is at least in size if possible, otherwise returns maximum available memory.
If is equal to 0, currently available memory would get returned.
Requests the that is at least in size if possible, otherwise returns maximum available memory.
If is equal to 0, currently available memory would get returned.
Owner of Memory that is responsible for disposing the underlying memory appropriately.
Returns a Memory.
Provides a mechanism for pinning and unpinning objects to prevent the GC from moving them.
Call this method to indicate that the IPinnable object can not be moved by the garbage collector.
The address of the pinned object can be taken.
The offset to the element within the memory at which the returned points to.
Call this method to indicate that the IPinnable object no longer needs to be pinned.
The garbage collector is free to move the object now.
A handle for the memory.
Creates a new memory handle for the memory.
pointer to memory
reference to manually managed object, or default if there is no memory manager
handle used to pin array buffers
Returns the pointer to memory, where the memory is assumed to be pinned and hence the address won't change.
Frees the pinned handle and releases IPinnable.
Manager of that provides the implementation.
Returns a .
Returns a span wrapping the underlying memory.
Returns a handle to the memory that has been pinned and hence its address can be taken.
The offset to the element within the memory at which the returned points to. (default = 0)
Lets the garbage collector know that the object is free to be moved now.
Returns a for the current .
The element count in the memory, starting at offset 0.
Returns a for the current .
The offset to the element which the returned memory starts at.
The element count in the memory, starting at element offset .
Returns an array segment.
Returns the default array segment if not overriden.
Implements IDisposable.
Clean up of any leftover managed and unmanaged resources.
Represents a pool of memory blocks.
Returns a singleton instance of a MemoryPool based on arrays.
Returns a memory block capable of holding at least elements of T.
If -1 is passed, this is set to a default value for the pool.
Returns the maximum buffer size supported by this pool.
Constructs a new instance of a memory pool.
Frees all resources used by the memory pool.
Frees all resources used by the memory pool.
This enum defines the various potential status that can be returned from Span-based operations
that support processing of input contained in multiple discontiguous buffers.
The entire input buffer has been processed and the operation is complete.
The input is partially processed, up to what could fit into the destination buffer.
The caller can enlarge the destination buffer, slice the buffers appropriately, and retry.
The input is partially processed, up to the last valid chunk of the input that could be consumed.
The caller can stitch the remaining unprocessed input with more data, slice the buffers appropriately, and retry.
The input contained invalid bytes which could not be processed. If the input is partially processed,
the destination contains the partial result. This guarantees that no additional data appended to the input
will make the invalid sequence valid.
Represents a sequence that can read a sequential series of .
Returns empty
Length of the .
Determines if the is empty.
Determines if the contains a single segment.
Gets from the first segment.
A position to the start of the .
A position to the end of the
Creates an instance of from linked memory list represented by start and end segments
and corresponding indexes in them.
Creates an instance of from the .
Creates an instance of from the , start and index.
Creates an instance of from the .
Consumer is expected to manage lifetime of memory until is not used anymore.
Forms a slice out of the given , beginning at , with items
The index at which to begin this slice.
The length of the slice
Forms a slice out of the given , beginning at , ending at (inclusive).
The index at which to begin this slice.
The end (inclusive) of the slice
Forms a slice out of the given , beginning at , with items
The starting (inclusive) at which to begin this slice.
The length of the slice
Forms a slice out of the given , beginning at , with items
The index at which to begin this slice.
The length of the slice
Forms a slice out of the given , beginning at , ending at (inclusive).
The index at which to begin this slice.
The end (inclusive) of the slice
Forms a slice out of the given , beginning at ', with items
The starting (inclusive) at which to begin this slice.
The length of the slice
Forms a slice out of the given , beginning at , ending at (inclusive).
The starting (inclusive) at which to begin this slice.
The ending (inclusive) of the slice
Forms a slice out of the given , beginning at , ending at the existing 's end.
The starting (inclusive) at which to begin this slice.
Forms a slice out of the given , beginning at , ending at the existing 's end.
The start index at which to begin this slice.
Returns an enumerator over the
Returns a new at an from the start of the sequence.
Returns a new at an from the
Tries to retrieve next segment after and return its contents in .
Returns false if end of was reached otherwise true.
Sets to the beginning of next segment if is set to true.
An enumerator over the
Initialize the enumerator.
The to enumerate.
The current
Moves to the next in the
Represents a linked list of nodes.
The value for current node.
The next node.
The sum of node length before current.
Represents a standard formatting string without using an actual String. A StandardFormat consists of a character (such as 'G', 'D' or 'X')
and an optional precision ranging from 0..99, or the special value NoPrecision.
Precision values for format that don't use a precision, or for when the precision is to be unspecified.
The maximum valid precision value.
The character component of the format.
The precision component of the format. Ranges from 0..9 or the special value NoPrecision.
true if Precision is a value other than NoPrecision
true if the StandardFormat == default(StandardFormat)
Create a StandardFormat.
A type-specific formatting character such as 'G', 'D' or 'X'
An optional precision ranging from 0..9 or the special value NoPrecision (the default)
Converts a character to a StandardFormat using the NoPrecision precision.
Converts a classic .NET format string into a StandardFormat
Converts a classic .NET format string into a StandardFormat
Returns true if both the Symbol and Precision are equal.
Compute a hash code.
Returns true if both the Symbol and Precision are equal.
Returns the format in classic .NET format.
Returns true if both the Symbol and Precision are equal.
Returns false if both the Symbol and Precision are equal.
Convert between binary data and UTF-8 encoded text that is represented in base 64.
Decode the span of UTF-8 encoded text represented as base 64 into binary data.
If the input is not a multiple of 4, it will decode as much as it can, to the closest multiple of 4.
The input span which contains UTF-8 encoded text in base 64 that needs to be decoded.
The output span which contains the result of the operation, i.e. the decoded binary data.
The number of input bytes consumed during the operation. This can be used to slice the input for subsequent calls, if necessary.
The number of bytes written into the output span. This can be used to slice the output for subsequent calls, if necessary.
True (default) when the input span contains the entire data to decode.
Set to false only if it is known that the input span contains partial data with more data to follow.
It returns the OperationStatus enum values:
- Done - on successful processing of the entire input span
- DestinationTooSmall - if there is not enough space in the output span to fit the decoded input
- NeedMoreData - only if isFinalBlock is false and the input is not a multiple of 4, otherwise the partial input would be considered as InvalidData
- InvalidData - if the input contains bytes outside of the expected base 64 range, or if it contains invalid/more than two padding characters,
or if the input is incomplete (i.e. not a multiple of 4) and isFinalBlock is true.
Returns the maximum length (in bytes) of the result if you were to deocde base 64 encoded text within a byte span of size "length".
Thrown when the specified is less than 0.
Decode the span of UTF-8 encoded text in base 64 (in-place) into binary data.
The decoded binary output is smaller than the text data contained in the input (the operation deflates the data).
If the input is not a multiple of 4, it will not decode any.
The input span which contains the base 64 text data that needs to be decoded.
The number of bytes written into the buffer.
It returns the OperationStatus enum values:
- Done - on successful processing of the entire input span
- InvalidData - if the input contains bytes outside of the expected base 64 range, or if it contains invalid/more than two padding characters,
or if the input is incomplete (i.e. not a multiple of 4).
It does not return DestinationTooSmall since that is not possible for base 64 decoding.
It does not return NeedMoreData since this method tramples the data in the buffer and
hence can only be called once with all the data in the buffer.
Encode the span of binary data into UTF-8 encoded text represented as base 64.
The input span which contains binary data that needs to be encoded.
The output span which contains the result of the operation, i.e. the UTF-8 encoded text in base 64.
The number of input bytes consumed during the operation. This can be used to slice the input for subsequent calls, if necessary.
The number of bytes written into the output span. This can be used to slice the output for subsequent calls, if necessary.
True (default) when the input span contains the entire data to decode.
Set to false only if it is known that the input span contains partial data with more data to follow.
It returns the OperationStatus enum values:
- Done - on successful processing of the entire input span
- DestinationTooSmall - if there is not enough space in the output span to fit the encoded input
- NeedMoreData - only if isFinalBlock is false, otherwise the output is padded if the input is not a multiple of 3
It does not return InvalidData since that is not possible for base 64 encoding.
Returns the maximum length (in bytes) of the result if you were to encode binary data within a byte span of size "length".
Thrown when the specified is less than 0 or larger than 1610612733 (since encode inflates the data by 4/3).
Encode the span of binary data (in-place) into UTF-8 encoded text represented as base 64.
The encoded text output is larger than the binary data contained in the input (the operation inflates the data).
The input span which contains binary data that needs to be encoded.
It needs to be large enough to fit the result of the operation.
The amount of binary data contained within the buffer that needs to be encoded
(and needs to be smaller than the buffer length).
The number of bytes written into the buffer.
It returns the OperationStatus enum values:
- Done - on successful processing of the entire buffer
- DestinationTooSmall - if there is not enough space in the buffer beyond dataLength to fit the result of encoding the input
It does not return NeedMoreData since this method tramples the data in the buffer and hence can only be called once with all the data in the buffer.
It does not return InvalidData since that is not possible for base 64 encoding.
Returns the symbol contained within the standard format. If the standard format
has not been initialized, returns the provided fallback symbol.
Fills a buffer with the ASCII character '0' (0x30).
Writes a value [ 0000 .. 9999 ] to the buffer starting at the specified offset.
This method performs best when the starting index is a constant literal.
Writes a value [ 00 .. 99 ] to the buffer starting at the specified offset.
This method performs best when the starting index is a constant literal.
We don't have access to Math.DivRem, so this is a copy of the implementation.
We don't have access to Math.DivRem, so this is a copy of the implementation.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Methods to format common data types as Utf8 strings.
Formats a Boolean as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G (default) True/False
l true/false
System.FormatException if the format is not valid for this data type.
Formats a DateTimeOffset as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
default 05/25/2017 10:30:15 -08:00
G 05/25/2017 10:30:15
R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
System.FormatException if the format is not valid for this data type.
Formats a DateTime as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G (default) 05/25/2017 10:30:15
R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
System.FormatException if the format is not valid for this data type.
Formats a Decimal as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential
System.FormatException if the format is not valid for this data type.
Formats a Double as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential
System.FormatException if the format is not valid for this data type.
Formats a Single as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential
System.FormatException if the format is not valid for this data type.
Formats a Guid as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
D (default) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
B {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
P (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)
N nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
System.FormatException if the format is not valid for this data type.
Used to provide access to the individual bytes of a GUID.
Formats a Byte as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats an SByte as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats a Unt16 as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats an Int16 as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats a UInt32 as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats an Int32 as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats a UInt64 as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats an Int64 as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Formats a TimeSpan as a UTF8 string.
Value to format
Buffer to write the UTF8-formatted value to
Receives the length of the formatted text in bytes
The standard format to use
true for success. "bytesWritten" contains the length of the formatted text in bytes.
false if buffer was too short. Iteratively increase the size of the buffer and retry until it succeeds.
Formats supported:
c/t/T (default) [-][d.]hh:mm:ss[.fffffff] (constant format)
G [-]d:hh:mm:ss.fffffff (general long)
g [-][d:][h]h:mm:ss[.f[f[f[f[f[f[f]]]]]] (general short)
System.FormatException if the format is not valid for this data type.
Methods to parse common data types to Utf8 strings.
Parses a Boolean at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G (default) True/False
l true/false
System.FormatException if the format is not valid for this data type.
Parses a DateTime at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
default 05/25/2017 10:30:15 -08:00
G 05/25/2017 10:30:15
R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
System.FormatException if the format is not valid for this data type.
Parses a DateTimeOffset at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G (default) 05/25/2017 10:30:15
R Tue, 03 Jan 2017 08:08:05 GMT (RFC 1123)
l tue, 03 jan 2017 08:08:05 gmt (Lowercase RFC 1123)
O 2017-06-12T05:30:45.7680000-07:00 (Round-trippable)
System.FormatException if the format is not valid for this data type.
Overflow-safe DateTimeOffset factory.
Overflow-safe DateTimeOffset factory.
Overflow-safe DateTimeOffset/Local time conversion factory.
Overflow-safe DateTime factory.
Parses a Decimal at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential
System.FormatException if the format is not valid for this data type.
Parses a Single at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential
System.FormatException if the format is not valid for this data type.
Parses a Double at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
F/f 12.45 Fixed point
E/e 1.245000e1 Exponential
System.FormatException if the format is not valid for this data type.
Parses a Guid at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
D (default) nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
B {nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn}
P (nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn)
N nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
System.FormatException if the format is not valid for this data type.
Parses a SByte at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses an Int16 at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses an Int32 at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses an Int64 at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses a Byte at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses a UInt16 at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses a UInt32 at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses a UInt64 at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
G/g (default)
D/d 32767
N/n 32,767
X/x 7fff
System.FormatException if the format is not valid for this data type.
Parses a TimeSpan at the start of a Utf8 string.
The Utf8 string to parse
Receives the parsed value
On a successful parse, receives the length in bytes of the substring that was parsed
Expected format of the Utf8 string
true for success. "bytesConsumed" contains the length in bytes of the substring that was parsed.
false if the string was not syntactically valid or an overflow or underflow occurred. "bytesConsumed" is set to 0.
Formats supported:
c/t/T (default) [-][d.]hh:mm:ss[.fffffff] (constant format)
G [-]d:hh:mm:ss.fffffff (general long)
g [-][d:]h:mm:ss[.f[f[f[f[f[f[f[]]]]]]] (general short)
System.FormatException if the format is not valid for this data type.
Parse the fraction portion of a TimeSpan. Must be 1..7 digits. If fewer than 7, zeroes are implied to the right. If more than 7, the TimeSpan
parser rejects the string (even if the extra digits are all zeroes.)
Overflow-safe TryCreateTimeSpan
Memory represents a contiguous region of arbitrary memory similar to .
Unlike , it is not a byref-like type.
Creates a new memory over the entirety of the target array.
The target array.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the memory.
The number of items in the memory.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Creates a new memory from a memory manager that provides specific method implementations beginning
at 0 index and ending at 'end' index (exclusive).
The memory manager.
The number of items in the memory.
Thrown when the specified is negative.
For internal infrastructure only
Creates a new memory from a memory manager that provides specific method implementations beginning
at 'start' index and ending at 'end' index (exclusive).
The memory manager.
The index at which to begin the memory.
The number of items in the memory.
Thrown when the specified or is negative.
For internal infrastructure only
Defines an implicit conversion of an array to a
Defines an implicit conversion of a to a
Defines an implicit conversion of a to a
Returns an empty
The number of items in the memory.
Returns true if Length is 0.
For , returns a new instance of string that represents the characters pointed to by the memory.
Otherwise, returns a with the name of the type and the number of elements.
Forms a slice out of the given memory, beginning at 'start'.
The index at which to begin this slice.
Thrown when the specified index is not in range (<0 or >=Length).
Forms a slice out of the given memory, beginning at 'start', of given length
The index at which to begin this slice.
The desired length for the slice (exclusive).
Thrown when the specified or end index is not in range (<0 or >=Length).
Returns a span from the memory.
Copies the contents of the memory into the destination. If the source
and destination overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
The Memory to copy items into.
Thrown when the destination is shorter than the source.
Copies the contents of the memory into the destination. If the source
and destination overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
If the destination is shorter than the source, this method
return false and no data is written to the destination.
The span to copy items into.
Creates a handle for the memory.
The GC will not move the memory until the returned
is disposed, enabling taking and using the memory's address.
An instance with nonprimitive (non-blittable) members cannot be pinned.
Copies the contents from the memory into a new array. This heap
allocates, so should generally be avoided, however it is sometimes
necessary to bridge the gap with APIs written in terms of arrays.
Determines whether the specified object is equal to the current object.
Returns true if the object is Memory or ReadOnlyMemory and if both objects point to the same array and have the same length.
Returns true if the memory points to the same array and has the same length. Note that
this does *not* check to see if the *contents* are equal.
Serves as the default hash function.
Extension methods for Span{T}, Memory{T}, and friends.
Extension methods for Span{T}, Memory{T}, and friends.
Removes all leading and trailing white-space characters from the span.
Removes all leading white-space characters from the span.
Removes all trailing white-space characters from the span.
Removes all leading and trailing occurrences of a specified character.
The source span from which the character is removed.
The specified character to look for and remove.
Removes all leading occurrences of a specified character.
The source span from which the character is removed.
The specified character to look for and remove.
Removes all trailing occurrences of a specified character.
The source span from which the character is removed.
The specified character to look for and remove.
Removes all leading and trailing occurrences of a set of characters specified
in a readonly span from the span.
The source span from which the characters are removed.
The span which contains the set of characters to remove.
If is empty, white-space characters are removed instead.
Removes all leading occurrences of a set of characters specified
in a readonly span from the span.
The source span from which the characters are removed.
The span which contains the set of characters to remove.
If is empty, white-space characters are removed instead.
Removes all trailing occurrences of a set of characters specified
in a readonly span from the span.
The source span from which the characters are removed.
The span which contains the set of characters to remove.
If is empty, white-space characters are removed instead.
Indicates whether the specified span contains only white-space characters.
Searches for the specified value and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The value to search for.
Searches for the specified sequence and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The sequence to search for.
Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The value to search for.
Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The sequence to search for.
Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
Searches for the specified value and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The value to search for.
Searches for the specified sequence and returns the index of its first occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The sequence to search for.
Searches for the specified value and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The value to search for.
Searches for the specified sequence and returns the index of its last occurrence. If not found, returns -1. Values are compared using IEquatable{T}.Equals(T).
The span to search.
The sequence to search for.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
One of the values to search for.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
The set of values to search for.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
One of the values to search for.
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
The set of values to search for.
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
One of the values to search for.
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
The set of values to search for.
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
One of the values to search for.
One of the values to search for.
One of the values to search for.
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. If not found, returns -1.
The span to search.
The set of values to search for.
Determines whether two sequences are equal by comparing the elements using IEquatable{T}.Equals(T).
Determines the relative order of the sequences being compared by comparing the elements using IComparable{T}.CompareTo(T).
Determines whether the specified sequence appears at the start of the span.
Determines whether the specified sequence appears at the start of the span.
Determines whether the specified sequence appears at the end of the span.
Determines whether the specified sequence appears at the end of the span.
Reverses the sequence of the elements in the entire span.
Creates a new span over the target array.
Creates a new Span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the Span.
The number of items in the Span.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Creates a new span over the portion of the target array segment.
Creates a new Span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the Span.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=segment.Count).
Creates a new Span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the Span.
The number of items in the Span.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=segment.Count).
Creates a new memory over the target array.
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the memory.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=array.Length).
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the memory.
The number of items in the memory.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Creates a new memory over the portion of the target array.
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the memory.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=segment.Count).
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the memory.
The number of items in the memory.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=segment.Count).
Copies the contents of the array into the span. If the source
and destinations overlap, this method behaves as if the original values in
a temporary location before the destination is overwritten.
The array to copy items from.
The span to copy items into.
Thrown when the destination Span is shorter than the source array.
Copies the contents of the array into the memory. If the source
and destinations overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
The array to copy items from.
The memory to copy items into.
Thrown when the destination is shorter than the source array.
Determines whether two sequences overlap in memory.
Determines whether two sequences overlap in memory and outputs the element offset.
Determines whether two sequences overlap in memory.
Determines whether two sequences overlap in memory and outputs the element offset.
Searches an entire sorted for a value
using the specified generic interface.
The element type of the span.
The sorted to search.
The to use when comparing.
The zero-based index of in the sorted ,
if is found; otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than or, if there is
no larger element, the bitwise complement of .
is .
Searches an entire sorted for a value
using the specified generic type.
The element type of the span.
The specific type of .
The sorted to search.
The to use when comparing.
The zero-based index of in the sorted ,
if is found; otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than or, if there is
no larger element, the bitwise complement of .
is .
Searches an entire sorted for the specified
using the specified generic type.
The element type of the span.
The specific type of .
The sorted to search.
The object to locate. The value can be null for reference types.
The to use when comparing.
///
The zero-based index of in the sorted ,
if is found; otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than or, if there is
no larger element, the bitwise complement of .
is .
Searches an entire sorted for a value
using the specified generic interface.
The element type of the span.
The sorted to search.
The to use when comparing.
The zero-based index of in the sorted ,
if is found; otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than or, if there is
no larger element, the bitwise complement of .
is .
Searches an entire sorted for a value
using the specified generic type.
The element type of the span.
The specific type of .
The sorted to search.
The to use when comparing.
The zero-based index of in the sorted ,
if is found; otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than or, if there is
no larger element, the bitwise complement of .
is .
Searches an entire sorted for the specified
using the specified generic type.
The element type of the span.
The specific type of .
The sorted to search.
The object to locate. The value can be null for reference types.
The to use when comparing.
///
The zero-based index of in the sorted ,
if is found; otherwise, a negative number that is the bitwise complement
of the index of the next element that is larger than or, if there is
no larger element, the bitwise complement of .
is .
Creates a new span over the portion of the target array.
Returns a value indicating whether the specified occurs within the .
The source span.
The value to seek within the source span.
One of the enumeration values that determines how the and are compared.
Determines whether this and the specified span have the same characters
when compared using the specified option.
The source span.
The value to compare with the source span.
One of the enumeration values that determines how the and are compared.
Compares the specified and using the specified ,
and returns an integer that indicates their relative position in the sort order.
The source span.
The value to compare with the source span.
One of the enumeration values that determines how the and are compared.
Reports the zero-based index of the first occurrence of the specified in the current .
The source span.
The value to seek within the source span.
One of the enumeration values that determines how the and are compared.
Copies the characters from the source span into the destination, converting each character to lowercase,
using the casing rules of the specified culture.
The source span.
The destination span which contains the transformed characters.
An object that supplies culture-specific casing rules.
If the source and destinations overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
Thrown when is null.
Copies the characters from the source span into the destination, converting each character to lowercase,
using the casing rules of the invariant culture.
The source span.
The destination span which contains the transformed characters.
If the source and destinations overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
Copies the characters from the source span into the destination, converting each character to uppercase,
using the casing rules of the specified culture.
The source span.
The destination span which contains the transformed characters.
An object that supplies culture-specific casing rules.
If the source and destinations overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
Thrown when is null.
Copies the characters from the source span into the destination, converting each character to uppercase
using the casing rules of the invariant culture.
The source span.
The destination span which contains the transformed characters.
If the source and destinations overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
Determines whether the end of the matches the specified when compared using the specified option.
The source span.
The sequence to compare to the end of the source span.
One of the enumeration values that determines how the and are compared.
Determines whether the beginning of the matches the specified when compared using the specified option.
The source span.
The sequence to compare to the beginning of the source span.
One of the enumeration values that determines how the and are compared.
Creates a new readonly span over the portion of the target string.
The target string.
Returns default when is null.
Creates a new readonly span over the portion of the target string.
The target string.
The index at which to begin this slice.
Returns default when is null.
Thrown when the specified index is not in range (<0 or >text.Length).
Creates a new readonly span over the portion of the target string.
The target string.
The index at which to begin this slice.
The desired length for the slice (exclusive).
Returns default when is null.
Thrown when the specified index or is not in range.
Creates a new over the portion of the target string.
The target string.
Returns default when is null.
Creates a new over the portion of the target string.
The target string.
The index at which to begin this slice.
Returns default when is null.
Thrown when the specified index is not in range (<0 or >text.Length).
Creates a new over the portion of the target string.
The target string.
The index at which to begin this slice.
The desired length for the slice (exclusive).
Returns default when is null.
Thrown when the specified index or is not in range.
Represents a contiguous region of memory, similar to .
Unlike , it is not a byref-like type.
Creates a new memory over the entirety of the target array.
The target array.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Creates a new memory over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the memory.
The number of items in the memory.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Creates a new memory over the existing object, start, and length. No validation is performed.
The target object.
The index at which to begin the memory.
The number of items in the memory.
Defines an implicit conversion of an array to a
Defines an implicit conversion of a to a
Returns an empty
The number of items in the memory.
Returns true if Length is 0.
For , returns a new instance of string that represents the characters pointed to by the memory.
Otherwise, returns a with the name of the type and the number of elements.
Forms a slice out of the given memory, beginning at 'start'.
The index at which to begin this slice.
Thrown when the specified index is not in range (<0 or >=Length).
Forms a slice out of the given memory, beginning at 'start', of given length
The index at which to begin this slice.
The desired length for the slice (exclusive).
Thrown when the specified or end index is not in range (<0 or >=Length).
Returns a span from the memory.
Copies the contents of the read-only memory into the destination. If the source
and destination overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
The Memory to copy items into.
Thrown when the destination is shorter than the source.
Copies the contents of the readonly-only memory into the destination. If the source
and destination overlap, this method behaves as if the original values are in
a temporary location before the destination is overwritten.
If the destination is shorter than the source, this method
return false and no data is written to the destination.
The span to copy items into.
Creates a handle for the memory.
The GC will not move the memory until the returned
is disposed, enabling taking and using the memory's address.
An instance with nonprimitive (non-blittable) members cannot be pinned.
Copies the contents from the memory into a new array. This heap
allocates, so should generally be avoided, however it is sometimes
necessary to bridge the gap with APIs written in terms of arrays.
Determines whether the specified object is equal to the current object.
Returns true if the memory points to the same array and has the same length. Note that
this does *not* check to see if the *contents* are equal.
Returns the hash code for this
Gets the state of the memory as individual fields.
The offset.
The count.
The object.
ReadOnlySpan represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed
or native memory, or to memory allocated on the stack. It is type- and memory-safe.
ReadOnlySpan represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed
or native memory, or to memory allocated on the stack. It is type- and memory-safe.
The number of items in the read-only span.
Returns true if Length is 0.
Returns false if left and right point at the same memory and have the same length. Note that
this does *not* check to see if the *contents* are equal.
This method is not supported as spans cannot be boxed. To compare two spans, use operator==.
Always thrown by this method.
This method is not supported as spans cannot be boxed.
Always thrown by this method.
Defines an implicit conversion of an array to a
Defines an implicit conversion of a to a
Returns a 0-length read-only span whose base is the null pointer.
Gets an enumerator for this span.
Enumerates the elements of a .
The span being enumerated.
The next index to yield.
Initialize the enumerator.
The span to enumerate.
Advances the enumerator to the next element of the span.
Gets the element at the current position of the enumerator.
Creates a new read-only span over the entirety of the target array.
The target array.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Creates a new read-only span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the read-only span.
The number of items in the read-only span.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Creates a new read-only span over the target unmanaged buffer. Clearly this
is quite dangerous, because we are creating arbitrarily typed T's
out of a void*-typed block of memory. And the length is not checked.
But if this creation is correct, then all subsequent uses are correct.
An unmanaged pointer to memory.
The number of elements the memory contains.
Thrown when is reference type or contains pointers and hence cannot be stored in unmanaged memory.
Thrown when the specified is negative.
Returns the specified element of the read-only span.
Thrown when index less than 0 or index greater than or equal to Length
Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference.
It can be used for pinning and is required to support the use of span within a fixed statement.
Copies the contents of this read-only span into destination span. If the source
and destinations overlap, this method behaves as if the original values in
a temporary location before the destination is overwritten.
The span to copy items into.
Thrown when the destination Span is shorter than the source Span.
Copies the contents of this read-only span into destination span. If the source
and destinations overlap, this method behaves as if the original values in
a temporary location before the destination is overwritten.
If the destination span is shorter than the source span, this method
return false and no data is written to the destination.
The span to copy items into.
Returns true if left and right point at the same memory and have the same length. Note that
this does *not* check to see if the *contents* are equal.
For , returns a new instance of string that represents the characters pointed to by the span.
Otherwise, returns a with the name of the type and the number of elements.
Forms a slice out of the given read-only span, beginning at 'start'.
The index at which to begin this slice.
Thrown when the specified index is not in range (<0 or >=Length).
Forms a slice out of the given read-only span, beginning at 'start', of given length
The index at which to begin this slice.
The desired length for the slice (exclusive).
Thrown when the specified or end index is not in range (<0 or >=Length).
Copies the contents of this read-only span into a new array. This heap
allocates, so should generally be avoided, however it is sometimes
necessary to bridge the gap with APIs written in terms of arrays.
This method is obsolete, use System.Runtime.InteropServices.MemoryMarshal.GetReference instead.
Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
would have been stored. Such a reference can be used for pinning but must never be dereferenced.
Provides a collection of methods for interoperating with , ,
, and .
Provides a collection of methods for interoperating with , ,
, and .
Get an array segment from the underlying memory.
If unable to get the array segment, return false with a default array segment.
Gets an from the underlying read-only memory.
If unable to get the type, returns false.
The element type of the .
The type of to try and retrive.
The memory to get the manager for.
The returned manager of the .
A indicating if it was successful.
Gets an and , from the underlying read-only memory.
If unable to get the type, returns false.
The element type of the .
The type of to try and retrive.
The memory to get the manager for.
The returned manager of the .
The offset from the start of the that the represents.
The length of the that the represents.
A indicating if it was successful.
Creates an view of the given to allow
the to be used in existing APIs that take an .
The element type of the .
The ReadOnlyMemory to view as an
An view of the given
Attempts to get the underlying from a .
The memory that may be wrapping a object.
The string.
The starting location in .
The number of items in .
Reads a structure of type T out of a read-only span of bytes.
Reads a structure of type T out of a span of bytes.
If the span is too small to contain the type T, return false.
Writes a structure of type T into a span of bytes.
Writes a structure of type T into a span of bytes.
If the span is too small to contain the type T, return false.
Creates a new memory over the portion of the pre-pinned target array beginning
at 'start' index and ending at 'end' index (exclusive).
The pre-pinned target array.
The index at which to begin the memory.
The number of items in the memory.
This method should only be called on an array that is already pinned and
that array should not be unpinned while the returned Memory is still in use.
Calling this method on an unpinned array could result in memory corruption.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Casts a Span of one primitive type to Span of bytes.
That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
The source slice, of type .
Thrown when contains pointers.
Thrown if the Length property of the new Span would exceed Int32.MaxValue.
Casts a ReadOnlySpan of one primitive type to ReadOnlySpan of bytes.
That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
The source slice, of type .
Thrown when contains pointers.
Thrown if the Length property of the new Span would exceed Int32.MaxValue.
Creates a from a .
The .
A representing the same memory as the , but writable.
must be used with extreme caution. is used
to represent immutable data and other memory that is not meant to be written to; instances created
by should not be written to. The method exists to enable variables typed
as but only used for reading to store a .
Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
would have been stored. Such a reference can be used for pinning but must never be dereferenced.
Returns a reference to the 0th element of the ReadOnlySpan. If the Span is empty, returns a reference to the location where the 0th element
would have been stored. Such a reference can be used for pinning but must never be dereferenced.
Casts a Span of one primitive type to another primitive type .
These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
Supported only for platforms that support misaligned memory access.
The source slice, of type .
Thrown when or contains pointers.
Casts a ReadOnlySpan of one primitive type to another primitive type .
These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
Supported only for platforms that support misaligned memory access.
The source slice, of type .
Thrown when or contains pointers.
Provides a collection of methods for interoperating with
Get from the underlying .
If unable to get the , return false.
Get an array segment from the underlying .
If unable to get the array segment, return false with a default array segment.
Get from the underlying .
If unable to get the , return false.
Get from the underlying .
If unable to get the , return false.
Represents position in non-contiguous set of memory.
Properties of this type should not be interpreted by anything but the type that created it.
Creates new
Returns object part of this
Returns integer part of this
Indicates whether the current is equal to another .
equality does not guarantee that they point to the same location in
Indicates whether the current is equal to another .
equality does not guarantee that they point to the same location in
Span represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed
or native memory, or to memory allocated on the stack. It is type- and memory-safe.
Span represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed
or native memory, or to memory allocated on the stack. It is type- and memory-safe.
The number of items in the span.
Returns true if Length is 0.
Returns false if left and right point at the same memory and have the same length. Note that
this does *not* check to see if the *contents* are equal.
This method is not supported as spans cannot be boxed. To compare two spans, use operator==.
Always thrown by this method.
This method is not supported as spans cannot be boxed.
Always thrown by this method.
Defines an implicit conversion of an array to a
Defines an implicit conversion of a to a
Returns an empty
Gets an enumerator for this span.
Enumerates the elements of a .
The span being enumerated.
The next index to yield.
Initialize the enumerator.
The span to enumerate.
Advances the enumerator to the next element of the span.
Gets the element at the current position of the enumerator.
Creates a new span over the entirety of the target array.
The target array.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Creates a new span over the portion of the target array beginning
at 'start' index and ending at 'end' index (exclusive).
The target array.
The index at which to begin the span.
The number of items in the span.
Returns default when is null.
Thrown when is covariant and array's type is not exactly T[].
Thrown when the specified or end index is not in the range (<0 or >=Length).
Creates a new span over the target unmanaged buffer. Clearly this
is quite dangerous, because we are creating arbitrarily typed T's
out of a void*-typed block of memory. And the length is not checked.
But if this creation is correct, then all subsequent uses are correct.
An unmanaged pointer to memory.
The number of elements the memory contains.
Thrown when is reference type or contains pointers and hence cannot be stored in unmanaged memory.
Thrown when the specified is negative.
Returns a reference to specified element of the Span.
Thrown when index less than 0 or index greater than or equal to Length
Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference.
It can be used for pinning and is required to support the use of span within a fixed statement.
Clears the contents of this span.
Fills the contents of this span with the given value.
Copies the contents of this span into destination span. If the source
and destinations overlap, this method behaves as if the original values in
a temporary location before the destination is overwritten.
The span to copy items into.
Thrown when the destination Span is shorter than the source Span.
Copies the contents of this span into destination span. If the source
and destinations overlap, this method behaves as if the original values in
a temporary location before the destination is overwritten.
If the destination span is shorter than the source span, this method
return false and no data is written to the destination.
The span to copy items into.
Returns true if left and right point at the same memory and have the same length. Note that
this does *not* check to see if the *contents* are equal.
Defines an implicit conversion of a to a
For , returns a new instance of string that represents the characters pointed to by the span.
Otherwise, returns a with the name of the type and the number of elements.
Forms a slice out of the given span, beginning at 'start'.
The index at which to begin this slice.
Thrown when the specified index is not in range (<0 or >=Length).
Forms a slice out of the given span, beginning at 'start', of given length
The index at which to begin this slice.
The desired length for the slice (exclusive).
Thrown when the specified or end index is not in range (<0 or >=Length).
Copies the contents of this span into a new array. This heap
allocates, so should generally be avoided, however it is sometimes
necessary to bridge the gap with APIs written in terms of arrays.
This method is obsolete, use System.Runtime.InteropServices.MemoryMarshal.GetReference instead.
Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
would have been stored. Such a reference can be used for pinning but must never be dereferenced.
Implements the copy functionality used by Span and ReadOnlySpan.
NOTE: Fast span implements TryCopyTo in corelib and therefore this implementation
is only used by portable span. The code must live in code that only compiles
for portable span which means either each individual span implementation
of this shared code file. Other shared SpanHelper.X.cs files are compiled
for both portable and fast span implementations.
Computes "start + index * sizeof(T)", using the unsigned IntPtr-sized multiplication for 32 and 64 bits.
Assumptions:
Start and index are non-negative, and already pre-validated to be within the valid range of their containing Span.
If the byte length (Span.Length * sizeof(T)) does an unsigned overflow (i.e. the buffer wraps or is too big to fit within the address space),
the behavior is undefined.
Determine if a type is eligible for storage in unmanaged memory.
Portable equivalent of RuntimeHelpers.IsReferenceOrContainsReferences{T}()
Equals() on Span and ReadOnlySpan is not supported. Use operator== instead.
GetHashCode() on Span and ReadOnlySpan is not supported.
Cannot use type '{0}'. Only value types without pointers or references are supported.
Destination is too short.
Memory<T> has been disposed.
Release all references before disposing this instance.
Format specifier was invalid.
The 'G' format combined with a precision is not supported.
Characters following the format symbol must be a number of {0} or less.
Precision cannot be larger than {0}.
Overlapping spans have mismatching alignment.
End position was not reached during enumeration.
Unexpected segment type.