|
GLG Toolkit, C / C++ API Library
Version 4.6
|
This group contains memory allocation functions as well as string utility functions. More...
This group contains memory allocation functions as well as string utility functions.
All returned values must be freed after use with GlgFree to avoid memory leaks.
Functions | |
| void * | GlgAlloc (GlgLong size) |
| Allocates memory using the Toolkit's memory allocator. More... | |
| char * | GlgConcatResNames (char *resource_name1, char *resource_name2) |
| Creates a composite resource path from two components. More... | |
| char * | GlgConcatStrings (char *string1, char *string2) |
| Concatenates two character strings. More... | |
| char * | GlgCreateIndexedName (char *template_name, GlgLong resource_index) |
| Creates a string with a name of an enumerated resource. More... | |
| void | GlgFree (void *ptr) |
| Frees memory used to store character strings or allocated using GlgAlloc. More... | |
| GlgBoolean | GlgPreAlloc (GlgLong size, GlgPreAllocType type) |
| Preallocates memory under the control of mission critical real-time applications. More... | |
| char * | GlgStrClone (char *string) |
| Creates a copy of a character string. More... | |
| void* GlgAlloc | ( | GlgLong | size | ) |
Allocates memory using the Toolkit's memory allocator.
The memory must be freed with GlgAlloc when it is no longer used.
| size | Specifies the size of a memory block in bytes. |
| char* GlgConcatResNames | ( | char * | resource_name1, |
| char * | resource_name2 | ||
| ) |
Creates a composite resource path from two components.
| resource_name1 | Specifies the first resource path component. |
| resource_name2 | Specifies the second resource path component. |
This function creates and returns a resource path formed by concatenating the two components with the / character between them. The function checks if a trailing / separator is already present in the first string, and adds it only if the separator is not present.
Either argument may be NULL, in which case the returned string will precisely equal the input value of the other argument.
The string containing the returned resource path should be freed later with GlgFree.
Examples
The following code:
produces the following output:
resource_path: DataGroup/DataSample2
Multiple calls to GlgConcatResNames may be used to create composite paths from more than two components:
producing the following output:
resource_path: DataGroup/DataSample2/Value
| char* GlgConcatStrings | ( | char * | string1, |
| char * | string2 | ||
| ) |
Concatenates two character strings.
| string1 | The first string to be concatenated. |
| string2 | The second string to be concatenated. |
This function creates a new string from two input strings. Either input string may be NULL, in which case the returned string is a copy of the non-NULL input string. If both strings are NULL, then NULL is returned.
The output of this function must be freed with GlgFree. GlgFree also handles NULL pointers, so the following code may be used without needing to check for NULL values:
string3 = GlgConcatStrings( string1, string2 ); ... GlgFree( string3 );
| char* GlgCreateIndexedName | ( | char * | template_name, |
| GlgLong | resource_index | ||
| ) |
Creates a string with a name of an enumerated resource.
| template_name | A character string containing the template name to be expanded. This name uses the % character to define the expansion position. |
| resource_index | Specifies the number to use for expanding the % character in the template name. |
This function creates and returns a resource name by replacing the first (leftmost) occurrence of the % expansion character within the template name with the number corresponding to the resource_index parameter. If the template name does not contain the expansion character, the number is added to the end of the name. The returned expanded name should later be freed with GlgFree.
Examples
The following code:
produces the following output:
Name: XLabelGroup/XLabel0/String Name: XLabelGroup/XLabel1/String Name: XLabelGroup/XLabel2/String
GlgCreateIndexedName may be used repeatedly if a template name has more than one expansion character. For example, the following code:
produces the following output:
Name: Chart4/Plots/Plot#3/Value
| void GlgFree | ( | void * | ptr | ) |
Frees memory used to store character strings or allocated using GlgAlloc.
| ptr | Specifies a memory pointer to be freed. |
This function is used to free memory allocated by GlgAlloc and GLG string utilities. This is not to be used to free the memory occupied by any GLG object (GlgObject). Use GlgDropObject and GlgReferenceObject to manage these objects.
The function checks for NULL address pointers, and will not fail or generate an error message if a NULL pointer is passed.
| GlgBoolean GlgPreAlloc | ( | GlgLong | size, |
| GlgPreAllocType | type | ||
| ) |
Preallocates memory under the control of mission critical real-time applications.
| size | The size of the memory to allocate. |
| type | The allocation type that controls the meaning of the size parameter:
|
Mission-critical applications can use this function to preallocate memory on start-up and then allocate more memory as needed outside of the application's critical sections.
The GlgGetLParameter function can be used to query the amount of spare memory in the preallocated memory blocks. If the buffers are not preallocated, they are allocated and automatically adjusted as needed.
| char* GlgStrClone | ( | char * | string | ) |
Creates a copy of a character string.
The copy should later be freed with GlgFree.
| string | The string to be copied. If a NULL pointer is passed, the return value will also be NULL. |