ByteBuffer
Description
- Derived from
-
Disposable abstract
IDisposableGeneric<ByteBuffer>
IMemoryConsumption
Represents a byte buffer.
The following figure illustrates the concepts used by a byte buffer:
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ Absolute byte offset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ Capacity = 16 bytes | | Position = 2 Limit = 10 (inclusive) (exclusive) \_____________________________/ Buffer range, Remaining = 10-2 = 8
Byte order for multi-byte data types is platform specific (e.g. little-endian for Intel x86).
The maximum capacity of a byte buffer is 2^31 bytes (i.e. 2 GB).
Public / Constructors
Allocate
Allocates a new byte buffer, panicking if not enough memory is available.
The Position of the newly created byte buffer will be zero and the Limit will be set to Capacity. The memory contents of the byte buffer will be initialized to zero.
- See also
Raw
Creates a raw byte pointer buffer.
Raw byte buffer do not hold any real memory. They are placeholders for existing memory regions of the given size in. The start address of a raw byte buffer must be specified via RawData.
Public / Methods
Clear
Sets the position of this buffer to zero and the limit to its capacity.
This method does not modify the buffer contents. To clear the buffer contents to zero, use Fill.
Compact
Returns a compact ByteBuffer that contains the data of this ByteBuffer between its current Position and Limit.
- See also
Copy
Copies count in bytes from this source buffer into the given target in buffer.
The method will read count in bytes from this source buffer, starting at sourcePosition in and will write them to the given target in buffer, beginning at targetPosition in. The current buffer positions and limits of both buffers will not be modified.
Flip
Flips the buffer by setting the limit to the current position and resetting the position to zero.
Get
2 overloads
Reads an 8-bit signed integer value from the current position and increases the position accordingly.
Reads an 8-bit signed integer value from the given absolute position.
GetBytes
2 overloads
Copies count opt bytes from this source buffer to the given target in buffer.
The method will read count opt bytes from this source buffer, starting at the current buffer position and will write them to the given target in buffer, beginning at the current buffer position. The current position of both buffers will be incremented by count opt. The buffer limits will not be modified.
Copying between raw byte buffers is not allowed (see IsRaw).
Reads bytes from this buffer and stores them in the given array.
GetDouble
2 overloads
Reads a 64-bit floating point value from the current position and increases the position accordingly.
Reads a 64-bit floating point value from the given position.
GetFloat
2 overloads
Reads a 32-bit floating point value from the current position and increases the position accordingly.
Reads a 32-bit floating point value from the given position.
GetInt
3 overloads
Reads a 32-bit signed integer value from the current position and increases the position accordingly.
Reads a signed 32-bit value from this buffer using the given byte order.
Reads a 32-bit signed integer value from the given position.
GetIntPtr
2 overloads
Reads a pointer value from the current position and increases the position accordingly.
- See also
Reads a pointer value from the given position.
- See also
GetLong
3 overloads
Reads a 64-bit signed integer value from the current position and increases the position accordingly.
Reads a signed 64-bit value from this buffer using the given byte order.
Reads a 64-bit signed integer value from the given position.
GetShort
3 overloads
Reads a 16-bit signed integer value from the current position and increases the position accordingly.
Reads a signed 16-bit value from this buffer using the given byte order.
Reads a 16-bit signed integer value from the given position.
Put
2 overloads
Writes an 8-bit signed integer value to the current position and increases the position accordingly.
Writes an 8-bit signed integer value to the given position.
PutBytes
2 overloads
Copies count opt bytes from the given source buffer to this target buffer.
The method will read count opt bytes from the given source buffer, starting at the current buffer position and will write them to this target buffer, beginning at the current buffer position. The current position of both buffers will be incremented by count opt. The buffer limits will not be modified.
Copying between raw byte buffers is not allowed (see IsRaw).
Writes the given bytes into this buffer.
PutDouble
2 overloads
Writes a 64-bit floating point value to the current position and increases the position accordingly.
Writes a 64-bit floating-point value to the given position.
PutFloat
2 overloads
Writes a 32-bit floating point value to the current position and increases the position accordingly.
Writes a 32-bit floating-point value to the given position.
PutInt
3 overloads
Writes a 32-bit signed integer value to the current position and increases the position accordingly.
Writes a signed 32-bit value to this buffer using the given byte order.
Writes a 32-bit signed integer value to the given position.
PutIntPtr
2 overloads
Writes a pointer value to the current position and increases the position accordingly.
Writes a pointer value to the given position.
PutLong
3 overloads
Writes a 64-bit signed integer value to the current position and increases the position accordingly.
Writes a signed 64-bit value to this buffer using the given byte order.
Writes a 64-bit signed integer value to the given position.
PutShort
3 overloads
Writes a 16-bit signed integer value to the current position and increases the position accordingly.
Writes a signed 16-bit value to this buffer using the given byte order.
Writes a 16-bit signed integer value to the given position.
ReadAsStream
Wraps this byte buffer in a data stream.
This byte buffer will end up as the IInternalBuffer.InternalBuffer of the returned MemoryDataStream object.
Public / Attributes
IsRaw
Is this a raw byte buffer?
Raw byte buffers are wrappers for memory regions that have been allocated by a third party (e.g. a locked vertex buffer region). The buffer itself does not hold ownership of the wrapped memory region and will hence perform no disposal whatsoever.
Limit
Gets or sets the buffer limit. If the position is larger than the new limit then it is set to the new limit.
RawLimit
Returns a memory pointer to the buffers current limit.
Use this property for interoperability with native code.