memory_management_operations.rst (1668B)
1 This chapter describes the global functions and macros you use to 2 perform memory management. NSPR provides heap-based memory management 3 functions that map to the familiar ``malloc()``, ``calloc()``, 4 ``realloc()``, and ``free()``. 5 6 - `Memory Allocation Functions <#Memory_Allocation_Functions>`__ 7 - `Memory Allocation Macros <#Memory_Allocation_Macros>`__ 8 9 .. _Memory_Allocation_Functions: 10 11 Memory Allocation Functions 12 --------------------------- 13 14 NSPR has its own heap, and these functions act on that heap. Libraries 15 built on top of NSPR, such as the Netscape security libraries, use these 16 functions to allocate and free memory. If you are allocating memory for 17 use by such libraries or freeing memory that was allocated by such 18 libraries, you must use these NSPR functions rather than the libc 19 equivalents. 20 21 Memory allocation functions are: 22 23 - :ref:`PR_Malloc` 24 - :ref:`PR_Calloc` 25 - :ref:`PR_Realloc` 26 - :ref:`PR_Free` 27 28 ``PR_Malloc()``, ``PR_Calloc()``, ``PR_Realloc()``, and ``PR_Free()`` 29 have the same signatures as their libc equivalents ``malloc()``, 30 ``calloc()``, ``realloc()``, and ``free()``, and have the same 31 semantics. (Note that the argument type ``size_t`` is replaced by 32 :ref:`PRUint32`.) Memory allocated by ``PR_Malloc()``, ``PR_Calloc()``, or 33 ``PR_Realloc()`` must be freed by ``PR_Free()``. 34 35 .. _Memory_Allocation_Macros: 36 37 Memory Allocation Macros 38 ------------------------ 39 40 Macro versions of the memory allocation functions are available, as well 41 as additional macros that provide programming convenience: 42 43 - :ref:`PR_MALLOC` 44 - :ref:`PR_NEW` 45 - :ref:`PR_REALLOC` 46 - :ref:`PR_CALLOC` 47 - :ref:`PR_NEWZAP` 48 - :ref:`PR_DELETE` 49 - :ref:`PR_FREEIF`