Buffer Object

Encapsulates a block of memory for use with advanced techniques such as DllCall, structures, StrPut and raw file I/O.

Buffer objects are typically created by calling BufferAlloc, but can also be returned by FileRead with the "RAW" option.

Buffer := BufferAlloc(ByteCount)

ClipboardAll returns a sub-type of Buffer, also named ClipboardAll.

Properties:

Buffer-like Objects

Some built-in functions accept a Buffer object in place of an address - see the Related section for links. These functions also accept any other object which has Ptr and Size properties, but are optimized for the native Buffer object.

In most cases, passing a Buffer object is safer than passing an address, as the function can read the buffer size to ensure that it does not attempt to access any memory location outside of the buffer. One exception is that DllCall calls functions outside of the program; in those cases, it may be necessary to explicitly pass the buffer size to the function.

Properties

Ptr

Retrieves the buffer's current memory address.

Ptr := Buffer.Ptr

Type: Integer

Any address returned by this property becomes invalid when the buffer is freed or reallocated. Invalid addresses must not be used. The buffer is not freed until the Buffer object's reference count reaches zero, but it is reallocated when its Size is changed.

Size

Retrieves or sets the buffer's size, in bytes.

ByteCount := Buffer.Size
Buffer.Size := ByteCount

Type: Integer

The buffer's address typically changes whenever its size is changed. If the size is decreased, the data within the buffer is truncated, but the remaining bytes are preserved. If the size is increased, all data is preserved and the values of any new bytes are arbitrary (they are not initialized, for performance reasons).

This property always returns the exact value it was given either by BufferAlloc or by a previous assignment.

BufferAlloc, DllCall, NumPut, NumGet, StrPut, StrGet, File.RawRead, File.RawWrite, ClipboardAll