HP-UX Directory Server 8.1 plug-in reference

Table Of Contents
23 Functions for managing memory
This chapter contains reference information on routines for managing memory, such as allocating
and freeing memory.
Table 23-1 Memory management routines
DescriptionFunction
Adds a new array.slapi_ch_array_add()
Frees an existing array.slapi_ch_array_free()
Makes a copy of an existing berval structure.
“slapi_ch_bvdup()”
Makes a copy of an array of existing berval structures.
“slapi_ch_bvecdup()”
Allocates space for an array of a number of elements of a specified size.“slapi_ch_calloc()”
Frees space allocated by the slapi_ch_malloc(), slapi_ch_realloc(),
and slapi_ch_calloc() functions.
“slapi_ch_free()”
Frees space previously allocated to a string.slapi_ch_free_string()
Allocates space in memory.slapi_ch_malloc()
Changes the size of a block of allocated memory.slapi_ch_realloc()
Creates, formats, and returns a given string.“slapi_ch_smprintf()”
Makes a copy of an existing string.slapi_ch_strdup()
23.1 slapi_ch_array_add()
Adds the given string to the given null-terminated array.
If the array is NULL, then the function creates a new array.
string is not copied, so if you want to add a copy of string to the array, use slapi_ch_strdup().
Then use slapi_ch_array_free() to free the array.
For example:
char **array = NULL;
...
slapi_ch_array_add(&array, slapi_ch_strdup("some string"));
...
slapi_ch_array_free(array);
Syntax
#include "slapi-plugin.h"
void slapi_ch_array_add(char ***array, char *string);
Parameters This function takes the following parameters:
Pointer to the array to be freed. If this parameter is NULL, then the function creates a
new array.
array
The string to add to the array.
string
23.2 slapi_ch_array_free()
This function frees the char ** pointed to by arrayp.
Syntax
23.1 slapi_ch_array_add() 205