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)
Type: String
The initial string.
Type: Integer
The writable capacity. When explicitly specified, the effective capacity is at least 16. If omitted, it is 256.
| Property | Type | Description |
|---|---|---|
Ptr | Integer | The address of the buffer's memory. Read-only. |
Pos | Integer | The 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. |
Capacity | Integer | The writable capacity, in characters, excluding the null terminator. Assigning to it reallocates the buffer, preserving existing content up to the new capacity. |
Size | Integer | The 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.
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
Receives formatted text directly into a StringBuffer.
sb := StringBuffer()
DllCall("wsprintf", "Ptr", sb, "Str", "%010d", "Int", 432, "Cdecl")
MsgBox sb ; 0000000432