MemBuffer object

The MemBuffer objects allow you to create a reserved memory space which can contain various binary values. MemBuffers are intended to be used in conjunction with external DLL libraries. Using MemBuffers you can define a structure with several values and pass the entire structure to and from a DLL function. The MemBuffer object can be created using the following syntax:

var Buffer = new MemBuffer(256); // create a memory buffer 256 bytes large


Конструкторы

MemBuffer Creates a new memory buffer of a specified size.

Методы

Operations
SetSize Resizes the memory buffer to the desired size.
Reading values
GetBool Reads a boolean value (1 byte) from memory buffer.
GetByte Reads an 8-bit integer value from memory buffer.
GetShort Reads a 16-bit integer value from memory buffer.
GetInt Reads a 32-bit integer value from memory buffer.
GetFloat Reads a 16-bit floating point value from memory buffer.
GetDouble Reads a 32-bit floating point value from memory buffer.
GetString Reads a string value from memory buffer.
GetPointer Reads a 32-bit memory-pointer value from memory buffer.
Storing values
SetBool Writes a boolean value (1 byte) to a memory buffer.
SetByte Writes an 8-bit integer value to a memory buffer.
SetShort Writes a 16-bit integer value to a memory buffer.
SetInt Writes a 32-bit integer value to a memory buffer.
SetFloat Writes a 16-bit floating point value to a memory buffer.
SetDouble Writes a 32-bit floating point value to a memory buffer.
SetString Writes a string value to a memory buffer.
SetPointer Writes a 32-bit memory pointer to a memory buffer.

Атрибуты

Type (только для чтения) Returns always "membuffer"
Length (только для чтения) Returns the current length of the associated memory space.

MemBuffer(Size)

Creates a new memory buffer of a specified size.

Параметры

Size
The size of memory to be allocated for this buffer, in bytes

SetSize(Size)

Resizes the memory buffer to the desired size.

Параметры

Size
Desired buffer size in bytes.

Возвращаемое значение

Returns true if the buffer has been successfuly resized.

Примечания

Resizing buffer to zero will free all memory associated with the buffer.


GetBool(Position)

Reads a boolean value (1 byte) from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns the value or null if Position is outside the buffer.


GetByte(Position)

Reads an 8-bit integer value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns the value or null if Position is outside the buffer.


GetShort(Position)

Reads a 16-bit integer value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns the value or null if Position is outside the buffer.


GetInt(Position)
GetLong(Position)

Reads a 32-bit integer value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns the value or null if Position is outside the buffer.


GetFloat(Position)

Reads a 16-bit floating point value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns the value or null if Position is outside the buffer.


GetDouble(Position)

Reads a 32-bit floating point value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns the value or null if Position is outside the buffer.


GetString(Position, Length)

Reads a string value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read
Length
Number of characters to read (optional)

Возвращаемое значение

Returns the value or null if Position is outside the buffer.

Примечания

If you don't specify the Length parameter the string is read until terminating zero or end of buffer is encountered (whichever comes first).


GetPointer(Position)

Reads a 32-bit memory-pointer value from memory buffer.

Параметры

Position
A position within the buffer from which the value is read

Возвращаемое значение

Returns a new MemBuffer object encapsulating the memory pointer or null if Position is outside the buffer.

Примечания

MemBuffer objects created by this method cannot be bound-checked, resized or saved. Be very careful when working with them.


SetBool(Position, Value)

Writes a boolean value (1 byte) to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.


SetByte(Position, Value)

Writes an 8-bit integer value to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.


SetShort(Position, Value)

Writes a 16-bit integer value to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.


SetInt(Position, Value)
SetLong(Position, Value)

Writes a 32-bit integer value to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.


SetFloat(Position, Value)

Writes a 16-bit floating point value to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.


SetDouble(Position, Value)

Writes a 32-bit floating point value to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.


SetString(Position, Value)

Writes a string value to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
The value to be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.

Примечания

The string is copied to the buffer including its zero terminating character.


SetPointer(Position, Value)

Writes a 32-bit memory pointer to a memory buffer.

Параметры

Position
A position within the buffer to which the value should be written
Value
A MemBuffer object whose address should be written to the buffer

Возвращаемое значение

Returns true if the value has been successfuly written.