str properties (lpstr, len, nc, flags)

str member variables:

 

lpstr - pointer to string.

len - length of string (number of bytes), not including terminating null character.

nc - size of string buffer.

flags:

1 (optimization) str functions should never free extra bytes. It means that allocated string memory can grow but not shrink. Use this flag to avoid frequent reallocations. However some functions may ignore it.
2 (optimization) str functions should allocate more extra bytes to avoid frequent reallocations.

4

(security)

QM 2.3.3. Erase string memory before freeing it. Use this flag for passwords and other confidential data. It makes much harder to retrieve the string from memory. To set this flag you can use this: str s; s.__set_secure. In older QM versions you would have to erase explicitly: str s="password"; ... s.set(0).

 

 

Remarks

When a str variable is just declared without initializing, all data members are 0.

 

To get string length of a str variable, use its len property.

 

When various operations are performed with a str variable, it's data members are managed automatically. You should not modify them. There are two cases when you can modify them:

 

1. You can modify flags to improve performance when multiple operations are performed with a str variable.

2. If you want to steal string buffer from a str variable, set lpstr to 0. To free the stealed memory, use q_free.

 

In C++, str definition would look like:

 

class str
{
public:
	LPSTR lpstr;
	int len, nc;
	BYTE flags;
//member functions
...
};

 

In QM, str definition would look like:

 

class str lpstr'lpstr len nc byte'flags

 

Example

str s = "string"
int i = s.len
 now i is 6
s.flags = 1
 now s buffer can grow, but not shrink