ARPDAS_QNX6 1.0
newmem.c
Go to the documentation of this file.
00001 /* newmem.c contains a simple new_memory() function. It is named
00002  * nl_new_memory() in order not to conflict with memlib.h, but
00003  * nortlib.h will define new_memory to be nl_new_memory if memlib.h
00004  * has not been included.
00005  */
00006 #include <stdlib.h>
00007 #include "nortlib.h"
00008 char rcsid_newmem_c[] =
00009   "$Header: /cvsroot/arp-das/nortlib2/src/newmem.c,v 1.3 2000/10/19 14:27:06 nort Exp $";
00010 
00011 void *new_memory(size_t size) {
00012   void *p;
00013   
00014   p = malloc(size);
00015   if (p == 0 && nl_response)
00016         nl_error(nl_response, "Memory allocation error");
00017   return p;
00018 }
00019 
00020 void nl_free_memory(void *p) {
00021   free(p);
00022 }
00023 /*
00024 =Name new_memory(): Safe memory allocation function
00025 =Subject Nortlib
00026 =Name nl_free_memory(): Safe memory free function
00027 =Subject Nortlib
00028 =Synopsis
00029 #include "nortlib.h"
00030 void *new_memory(size_t size);
00031 void nl_free_memory(void *p);
00032 
00033 =Description
00034 
00035   new_memory() is a thin cover for malloc() that guarantees
00036   a non-NULL return. If memory allocation fails, new_memory()
00037   will terminate the program by calling =nl_error=(3).
00038   
00039 =Returns
00040 
00041   Returns a newly allocated copy of the argument string.
00042   If memory allocation fails, the program will terminate
00043   via =nl_error=(3).
00044   
00045   new_memory() uses the same name as a function in the memlib
00046   library which provides more sophisticated memory allocation
00047   strategies, including hooks for garbage collection or a limited
00048   form of virtual memory.
00049   
00050   nl_free_memory() is an extremely thin cover for free().
00051 
00052 =SeeAlso
00053   =nl_response=, =nl_strdup=().
00054 =End
00055 */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines