Allocate or free string buffer

Syntax1 - allocate

s.all(length [flags] [fillchar])

 

Syntax2 - compact

s.all(-1)

 

Syntax3 - free

s.all

 

Parameters

s - str variable.

length - number of bytes to allocate, not including the terminating null character.

flags:

1 Preserve previous string (max length bytes).
2 Set string length (len property) to length. If this flag not used, len will be 0 or length of preserved string.

fillchar - character to fill allocated string (except preserved part). If omitted, allocated string content is undefined. In Unicode mode fillchar must be an ASCII character.

 

Remarks

Syntax1

Allocates string buffer (memory).

 

Sets nc property to the number of allocated bytes, not including the terminating null character.

 

For better performance, may allocate more than length bytes.

 

Syntax2

Compacts string buffer. It frees extra memory that may be added or not freed by other string functions. Extra memory is used to avoid frequent reallocations.

 

Syntax3

Frees string buffer. Sets lpstr, len and length properties to 0.

 

See also: str.fix.

 

Tips

Function all can be used to allocate buffer before calling a dll function that requires pointer to buffer. When dll function returns, use function fix without length or with length = dll function's return value.

 

Example

int hwnd = win()
str s
s.all(256)
int i = GetWindowText(hwnd s 256)
s.fix(i)
 or:
str s.fix(GetWindowText(win() s.all(256) 256))