Table of Contents


allocate, reallocate - memory allocation with error control.


    #include <stdinc.h>
    void *allocate(int nb);
    void *reallocate(void *bp, int nb);


allocate and reallocate are the NEMO counterparts of calloc(3) and realloc(3) , but with guaranteed to return a sufficient amount of memory. The caller does not have to do any error control, instead the NEMO routines will call error(3NEMO) and in general exit when memory is exhausted.

This would also be the place to replace you malloc routine with another one, see


Here is an example of allocating a simple 1D array, after which the size is increased. All failures in allocation will result in a call to error(3NEMO) .
    int n = 1000;
    double *x = allocate(n * sizeof(double));
    x = reallocate(x,2000);


Although NEMO program should all call allocate instead of the system routine malloc(3) , there are a few places left where malloc is called since failure to allocate must be caught immediately. We don’t supply a good solution to this, other than error control (see error(3NEMO) ).


5-mar-94    man created     PJT
5-may-03    added an example    PJT
19-sep-03    documented that calloc is used (since april 2001)    PJT

Table of Contents