StringBuffer Object

class StringBuffer extends Object

Provides writable string memory for DllCall, NumPut and other pointer-based operations. It is implicitly convertible to String.

Buffer := StringBuffer(InitialValue := "", Capacity := 256)

Parameters

InitialValue

Type: String

The initial string.

Capacity

Type: Integer

The writable capacity. When explicitly specified, the effective capacity is at least 16. If omitted, it is 256.

Properties

PropertyTypeDescription
PtrIntegerThe address of the buffer's memory. Read-only.
PosIntegerThe current read/write position, in characters. Assigning a negative value moves the position to the end of the current string by scanning for its null terminator; any other value is clamped to Capacity.
CapacityIntegerThe writable capacity, in characters, excluding the null terminator. Assigning to it reallocates the buffer, preserving existing content up to the new capacity.
SizeIntegerThe capacity in bytes, excluding the null terminator: Capacity multiplied by the size of one character in the buffer's encoding. Read-only.

Capacity counts characters while Size counts bytes, so for the default Unicode encoding Size is twice Capacity. The functions which transfer raw memory — File.RawRead, File.RawWrite and a File opened over memory — locate a target through its Ptr and Size, so they measure in bytes.

Remarks

StringBuffer uses the managed StringBuilder representation used by .NET platform invocation for writable string pointers. Prefer it over StrPtr when native code writes into a string.

sb := StringBuffer("hello")
MsgBox sb

Examples

Receives formatted text directly into a StringBuffer.

sb := StringBuffer()
DllCall("wsprintf", "Ptr", sb, "Str", "%010d", "Int", 432, "Cdecl")
MsgBox sb  ; 0000000432

DllCall, Buffer, StrGet, StrPtr