op_prg_mem_realloc()
Abstract
Re-allocates an existing block of general-purpose memory with a new size.
Note: This KP is a macro call included for backward compatibility only. Use prg_mem_realloc() in new code.
Syntax
op_prg_mem_realloc (mem_ptr, size)
| Argument | Type | Description |
|---|---|---|
mem_ptr |
void* |
The existing memory block to be re-allocated. |
size |
size_t |
Number of bytes requested for the memory re-allocation. |
Return Type
void*
Pointer to the re-allocated block of memory. OPC_NIL is returned if the memory re-allocation fails.
This “generic” pointer should be cast into the appropriate data type for further access.
Example
/* re-allocate the document request message */
doc_req_msg = (Doc_Req_Msg *) op_prg_mem_realloc (doc_req_msg,
sizeof (Big_Doc_Req_Msg));
Details
If no memory block is specified (mem_ptr is OPC_NIL), this function acts like op_prg_mem_alloc().
If size is bigger than the previously allocated memory block, the existing memory contents are unchanged and the additional space is filled with zeros.
Purpose
Provides a mechanism to dynamically re-allocate memory with a new size. This function is similar to the realloc() function.
Errors
- Recoverable Error: Request to re-allocate (
<size>bytes) of Prg memory failed.
Reference
- use op_prg_mem_free() to deallocate a previously allocated block of memory