RTI Connext Traditional C++ API
Version 5.3.0
|
<<extension>> String creation, cloning, assignment, and deletion. More...
Functions | |
char * | DDS_String_alloc (size_t length) |
Create a new empty string that can hold up to length characters. | |
char * | DDS_String_dup (const char *str) |
Clone a string. Creates a new string that duplicates the value of string . | |
void | DDS_String_free (char *str) |
Delete a string. | |
DDS_Wchar * | DDS_Wstring_alloc (DDS_UnsignedLong length) |
Create a new empty string that can hold up to length wide characters. | |
DDS_UnsignedLong | DDS_Wstring_length (const DDS_Wchar *str) |
Get the number of wide characters in the given string. | |
DDS_Wchar * | DDS_Wstring_copy (DDS_Wchar *dst, const DDS_Wchar *src) |
Copy the source string over the destination string reallocating the space if it's necessary. | |
DDS_Wchar * | DDS_Wstring_copy_and_widen (DDS_Wchar *dst, const char *src) |
Copy the source string over the destination string, widening each character. | |
DDS_Wchar * | DDS_Wstring_dup (const DDS_Wchar *str) |
Clone a string of wide characters. Creates a new string that duplicates the value of string . | |
DDS_Wchar * | DDS_Wstring_dup_and_widen (const char *str) |
Clone a string of characters as a string of wide characters. | |
void | DDS_Wstring_free (DDS_Wchar *str) |
Delete a string. | |
<<extension>> String creation, cloning, assignment, and deletion.
The methods in this class ensure consistent cross-platform implementations for string creation (DDS_String_alloc()), deletion (DDS_String_free()), and cloning (DDS_String_dup()) that preserve the mutable value type semantics. These are to be viewed as methods that define a string
class whose data is represented by a 'char*'
.
The following conventions govern the memory management of strings in RTI Connext.
string
class methods. The representation of a string in C/C++ unfortunately does not allow programs to detect how much memory has been allocated for a string. RTI Connext must therefore make some assumptions when a user requests that a string be copied into. The following rules apply when RTI Connext is copying into a string or string sequence:
This requirement can generally be assured by adhering to the following idiom for manipulating strings.
Not adhering to this idiom can result in bad pointers, and incorrect memory being freed.
In addition, the user code should be vigilant to avoid memory leaks. It is good practice to:
char* DDS_String_alloc | ( | size_t | length | ) |
Create a new empty string that can hold up to length
characters.
A string created by this method must be deleted using DDS_String_free(). This function will allocate enough memory to hold a string of \p length characters, \b plus one additional byte to hold the NULL terminating character.
length | <<in>> Capacity of the string. |
char* DDS_String_dup | ( | const char * | str | ) |
Clone a string. Creates a new string that duplicates the value of string
.
A string created by this method must be deleted using DDS_String_free()
str | <<in>> The string to duplicate. |
string
== NULL, this method always returns NULL. Otherwise, upon success it returns a newly created string whose value is string
; upon failure it returns NULL. void DDS_String_free | ( | char * | str | ) |
Delete a string.
string
must be either NULL, or must have been created using DDS_String_alloc(), DDS_String_dup()str | <<in>> The string to delete. |
DDS_Wchar* DDS_Wstring_alloc | ( | DDS_UnsignedLong | length | ) |
Create a new empty string that can hold up to length
wide characters.
A string created by this method must be deleted using DDS_Wstring_free()
This function will allocate enough memory to hold a string of length
characters, plus one additional wide character to hold the NULL terminator.
length | <<in>> Capacity of the string. |
DDS_UnsignedLong DDS_Wstring_length | ( | const DDS_Wchar * | str | ) |
Get the number of wide characters in the given string.
The result does not count the terminating zero character.
str | <<in>> A non-NULL string. |
Copy the source string over the destination string reallocating the space if it's necessary.
dst | |
src |
dst
Clone a string of wide characters. Creates a new string that duplicates the value of string
.
A string created by this method must be deleted using DDS_Wstring_free().
str | <<in>> The string to duplicate. |
string
== NULL, this method always returns NULL. Otherwise, upon success it returns a newly created string whose value is string
; upon failure it returns NULL. DDS_Wchar* DDS_Wstring_dup_and_widen | ( | const char * | str | ) |
Clone a string of characters as a string of wide characters.
A string created by this method must be deleted using DDS_Wstring_free()
str | <<in>> The string to duplicate. |
string
== NULL, this method always returns NULL. Otherwise, upon success it returns a newly created string whose value is string
; upon failure it returns NULL. void DDS_Wstring_free | ( | DDS_Wchar * | str | ) |
Delete a string.
string
must either NULL, or must have been created using DDS_Wstring_alloc(), DDS_Wstring_dup(), or DDS_Wstring_replace()str | <<in>> The string to delete. |