op_prg_cmo_dealloc()
Abstract
Deallocates a block of categorized memory that was previously allocated.
Note: This KP is a macro call included for backward compatibility only. Use prg_mem_free() in new code.
Syntax
op_prg_cmo_dealloc (ptr)
| Argument | Type | Description |
|---|---|---|
ptr |
void* |
Pointer to the categorized memory object to be deallocated. |
Return Type
void
No return value.
Example
/* Allocate categorized memory object */
cmo_ptr = op_prg_cmo_alloc (host_cmo, strlen (orig_name) + 1);
/* Use categorized memory */
...
/* Finished with categorized memory, so deallocate */
if (cmo_ptr != OPC_NIL)
op_prg_cmo_dealloc (cmo_ptr);
Details
Memory that is dynamically allocated should be deallocated if it is no longer useful in the simulation, so that it can be recycled for other purposes. Short-lived data structures that are created during simulation or program execution will build up memory usage if not deallocated, and can cause an unnecessary abort due to lack of memory. The user is responsible for ensuring that NIL or uninitialized pointers are not passed to op_prg_cmo_dealloc(). Other invalid pointers include statically declared memory such as global or temporary function variables.
Purpose
Provides a mechanism for recycling dynamically-allocated memory that has finished serving its purpose in the simulation or program execution.
Errors
- None.
Reference
- use op_prg_cmo_define() to define a new type of categorized memory object or obtain a categorized memory object handle
- use op_prg_cmo_alloc() to allocate an object using a categorized memory object handle
- use op_prg_mem_alloc() to allocate generic (non-categorized) memory
- use op_prg_mem_copy() to copy a block of memory