Click or drag to resize

StringAlloc Function

X#
Copy a string to a newly allocated block of memory and return a PSZ to the memory.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION StringAlloc(
	cString AS STRING
) AS PSZ
Request Example View Source

Parameters

cString
Type: String
The string to copy.

Return Value

Type: Psz
A pointer to the newly allocated string.
Remarks
StringAlloc() makes a copy of a string.
The new copy is a PSZ and points to a different address from the original string.
The newly allocated string is a static object which will not be moved by the garbage collector. Note that storage allocated by StringAlloc() must be removed by MemFree().
Remarks
Tip Tip
The PSZ type is included in the X# language and runtime for compatibility only. In most cases the type can and should be replaced with normal strings.
If you need to interface with Win32 API functions that expect an ansi string, there is often also an alternative with a unicode string. We recommend to use that alternative when possible.
Examples
This example displays the storage addresses of two variables:
X#
1LOCAL pszString AS PSZ
2LOCAL cString AS STRING
3cString := "CAVO2x tree"
4pszString := StringAlloc(cString)
5? @cString
6? @pszString        // Has different storage address than cString
7MemFree(pszString)
See Also