#includevoid MyFunctionL() { // Allocate memory for a constant string const TDesC8& myString = _L8("Hello, World!").AllocL(); // Use the string // ... // Free the allocated memory delete &myString; }
#includeIn this example, we pass a C-style string to a function that uses it to create a TPtrC8 object. We then call AllocL to allocate memory for the object. The return value is a reference to a constant TDesC8 object that points to the allocated memory. We can use this object like any other string. When we are finished using the string, we delete the reference to free the allocated memory. Package library: e32std.libvoid MyFunctionL(const char* str) { // Allocate memory for a variable-length string TPtrC8 myString(reinterpret_cast (str), strlen(str)).AllocL(); // Use the string // ... // Free the allocated memory delete &myString; }