Wrap Memory Allocator
Provide application specific enhancements to the system's
standard memory allocator.
Notes
The malloc() and realloc() functions are wrappered,
but the free() function is used "bare".
- Define xmalloc()
-
Function definition
- Segment Source
-
276: /* Allocate N bytes of memory dynamically, with error checking. */
277:
278: static char *
279: xmalloc (unsigned int n)
280: {
281: char *p;
282:
283: p = malloc (n);
284: if (p == 0)
285: {
286: error (0, 0, _("virtual memory exhausted"));
287: cleanup ();
288: exit (SORT_FAILURE);
289: }
290: return p;
291: }
292:
- Define xrealloc()
-
Function definition
- Segment Source
-
293: /* Change the size of an allocated block of memory P to N bytes,
294: with error checking.
295: If P is NULL, run xmalloc.
296: If N is 0, run free and return NULL. */
297:
298: static char *
299: xrealloc (char *p, unsigned int n)
300: {
301: if (p == 0)
302: return xmalloc (n);
303: if (n == 0)
304: {
305: free (p);
306: return 0;
307: }
308: p = realloc (p, n);
309: if (p == 0)
310: {
311: error (0, 0, _("virtual memory exhausted"));
312: cleanup ();
313: exit (SORT_FAILURE);
314: }
315: return p;
316: }
317: