|
NSPR Reference Previous Contents Next |
malloc, calloc, realloc, and free.
Memory Allocation Functions
Memory Allocation Macros
libc equivalents.
Memory allocation functions are:
PR_Malloc
PR_Calloc
PR_Realloc
PR_Free
PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free have the same signatures as
their libc equivalents malloc, calloc, realloc, and free, and have the same
semantics. (Note that the argument type size_t is replaced by PRUint32.)
Memory allocated by PR_Malloc, PR_Calloc, or PR_Realloc must be freed by
PR_Free.
#include <prmem.h>
void * PR_Malloc (PRUint32 size);
|
size
|
Size in bytes of memory to be allocated.
|
NULL. Call PR_GetError to retrieve the error returned by the libc function malloc.
#include <prmem.h>
void *PR_Calloc (
PRUint32 nelem,
PRUint32 elsize);
nelem
|
The number of elements of size elsize to be allocated.
|
elsize
|
The size of an individual element.
|
NULL. Call PR_GetError to retrieve the error returned by the libc function calloc.
#include <prmem.h>
void *PR_Realloc (
void *ptr,
PRUint32 size);
ptr
|
A pointer to the existing memory block being resized.
|
size
|
The size of the new memory block.
|
NULL. Call PR_GetError to retrieve the error returned by the libc function
realloc.
ptr to
a new size. The contents of the specified memory remains the same up to the
smaller of its old size and new size, although the new memory block's address can
be different from the original address.
#include <prmem.h>
void PR_Free(void *ptr);
ptr
|
A pointer to the memory to be freed.
|
ptr to the heap.
PR_MALLOC
PR_NEW
PR_REALLOC
PR_CALLOC
PR_NEWZAP
PR_DELETE
PR_FREEIF
#include <prmem.h>
void * PR_MALLOC(_bytes);
_bytes
|
Size of the requested memory block.
|
NULL. Call PR_GetError to retrieve the error returned by the libc function malloc.
#include <prmem.h>
_type * PR_NEW(_struct);
_struct
|
The name of a type.
|
_type or NULL on error. Call PR_GetError to retrieve the error
returned by the libc function.
sizeof(_struct) and returns a
pointer to that memory.
#include <prmem.h>
void * PR_REALLOC(_ptr, _size);
_ptr
|
pointer of memory to be re-sized.
|
_size
|
The requested new size.
|
NULL.
Call PR_GetError to retrieve the error returned by the libc function realloc.
PR_Realloc.
#include <prmem.h>
void * PR_CALLOC(_size);
_size
|
The size of memory to be allocated.
|
NULL. Call PR_GetError to retrieve the error returned by the libc function calloc.
#include <prmem.h>
(_type *) PR_NEWZAP(_struct);
_struct
|
The name of a type.
|
sizeof(_type) whose contents are set to zero, or
NULL on error. Call PR_GetError to retrieve the error returned by the libc
function.
#include <prmem.h>
void PR_DELETE(_ptr);
_ptr
|
The address of memory to be returned to the heap. Must be an lvalue
(an expression that can appear on the left side of an assignment
statement).
|
_ptr to NULL.
#include <prmem.h>
void PR_FREEIF(_ptr);
_ptr
|
The address of memory to be returned to the heap.
|
_ptr is not NULL. If _ptr is NULL, the
macro has no effect.
Last Updated May 18, 2001