Source code location: | Utilities/Memory |
Function prototypes file: | Utilities/Memory/zoltan_mem.h or include/zoltan_mem.h |
Library name: | libzoltan_mem.a |
Other libraries used by this library: | libmpi.a. (See note below.) |
Routines:
Zoltan_Array_Alloc: Allocates arrays of dimension n, n=0,1,...,4 |
|
Use in Zoltan:
The memory management utility routines are used extensively in Zoltan and in some individual algorithms. Zoltan developers use these routines directly for most memory management, taking advantage of the error checking and debugging capabilities of the library. |
|
Note on MPI usage:
MPI is used only to obtain the processor number (through a call to MPI_Comm_rank) for print statements and error messages. If an application does not link with MPI, the memory utilities should be compiled with -DZOLTAN_NO_MPI; all output will then appear to be from processor zero, even if it is actually from other processors. |
Arguments: | |
file | A string containing the name of the file calling the function. The __FILE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
line | The line number within file of the call to the function. The __LINE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
n | The number of dimensions in the array to be allocated. Valid values are 0, 1, 2, 3, or 4. |
d1, d2, ..., dn | The size of each dimension to be allocated. One argument is included for each dimension. |
size | The size (in bytes) of the data objects to be stored in the array. |
Returned Value: | |
double * | A pointer to the starting address of the n-dimensional array, or NULL if the allocation fails. |
Example: | |
int ** x = (int **) Zoltan_Array_Alloc ( __FILE__ , __LINE__ , 2, 5, 6, sizeof (int)); | |
Allocates a two-dimensional, 5x6-element array of integers. |
A macro ZOLTAN_MALLOC is defined in zoltan_mem.h. It takes the argument n, and adds the __FILE__ and __LINE__ macros to the argument list of the Zoltan_Malloc call:
#define ZOLTAN_MALLOC(n) Zoltan_Malloc((n), __FILE__, __LINE__)Using this macro, the developer gains the file and line debugging information without having to type file and line information in each memory allocation call.
Arguments: | |
n | The size (in bytes) of the memory-allocation request. |
file | A string containing the name of the file calling the function. The __FILE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
line | The line number within file of the call to the function. The __LINE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
Returned Value: | |
double * | A pointer to the starting address of memory allocated. NULL is returned if n = 0 or the routine is unsuccessful. |
Example: | |
struct Zoltan_Struct *b = (struct Zoltan_Struct *) ZOLTAN_MALLOC(sizeof(struct Zoltan_Struct)); | |
Allocates memory for one Zoltan_Struct data structure. |
A macro ZOLTAN_CALLOC is defined in zoltan_mem.h. It takes the arguments num and size, and adds the __FILE__ and __LINE__ macros to the argument list of the Zoltan_Calloc call:
#define ZOLTAN_CALLOC(num, size) Zoltan_Calloc((num), (size), __FILE__, __LINE__)Using this macro, the developer gains the file and line debugging information without having to type file and line information in each memory allocation call.
Arguments: | |
num | The number of elements of the following size to allocate. |
size | The size of each element. Hence, the total allocation is num * size bytes. |
file | A string containing the name of the file calling the function. The __FILE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
line | The line number within file of the call to the function. The __LINE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
Returned Value: | |
double * | A pointer to the starting address of memory allocated. NULL is returned if n = 0 or the routine is unsuccessful. |
Example: | |
int *b = (int *) ZOLTAN_CALLOC( 10, sizeof(int)); | |
Allocates memory for 10 integers and initializes the memory to zeros. |
A macro ZOLTAN_REALLOC is defined in zoltan_mem.h. It takes the arguments ptr and n, and adds the __FILE__ and __LINE__ macros to the argument list of the Zoltan_Realloc call:
#define ZOLTAN_REALLOC(ptr, n) Zoltan_Realloc((ptr), (n), __FILE__, __LINE__)Using this macro, the developer gains the file and line debugging information without having to type file and line information in each memory allocation call.
Arguments: | |
ptr | Pointer to allocated memory to be re-sized. |
n | The size (in bytes) of the memory-allocation request. |
file | A string containing the name of the file calling the function. The __FILE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
line | The line number within file of the call to the function. The __LINE__ macro can be passed as this argument. This argument is useful for debugging memory allocation problems. |
Returned Value: | |
double * | A pointer to the starting address of memory allocated. If the routine is unsuccessful, NULL is returned and *ptr is unchanged. |
Example: | |
int n = sizeof(struct Zoltan_Struct);
int *b = (int *) ZOLTAN_MALLOC (n)); b = (int *) ZOLTAN_REALLOC (b, 2*n); |
|
Reallocates memory for b from length n to length 2*n. |
A macro ZOLTAN_FREE is defined in zoltan_mem.h. It takes the argument ptr, and adds the __FILE__ and __LINE__ macros to the argument list of the Zoltan_Free call:
#define ZOLTAN_FREE(ptr) Zoltan_Free((void **)(ptr), __FILE__, __LINE__)Using this macro, the developer gains the file and line debugging information without having to type file and line information in each memory allocation call.
Arguments: | |
ptr | Address of a pointer to the memory to be freed. Upon return, ptr is set to NULL. |
Example: | |
ZOLTAN_FREE(& x); | |
Frees memory associated with the variable x; upon return, x is NULL. |
Arguments: | |
new_level | Integer indicating the amount of debugging to use.  Valid options include:
0 -- No debugging. |
Default: | |
Memory debug level is 1. |
Arguments: | |
None. |
Arguments: | |
type | Integer to request type of information required.  These integers
are defined in zoltan_mem.h. Valid options include:
ZOLTAN_MEM_STAT_TOTAL -- The function will return the current total memory allocated via Zoltan's memory allocation routines. |
Default: | |
type = ZOLTAN_MEM_STAT_MAXIMUM | Returned Value: |
int | The number in bytes of the specific requested memory statistic. |
Example: | |
total = Zoltan_Memory_Usage (ZOLTAN_MEM_STAT_TOTAL); |
Arguments: | |
type | Integer to specify the type of information to be reset .  These integers
are defined in zoltan_mem.h. Valid options include:
ZOLTAN_MEM_STAT_TOTAL -- The function will set the count of total memory allocated via Zoltan's memory allocation routines to zero. |
Default: | |
type = ZOLTAN_MEM_STAT_MAXIMUM | |
Example: | |
Zoltan_Memory_Reset (ZOLTAN_MEM_STAT_TOTAL); |