The alloc() Function
Many programs I’ve worked on use very few direct calls to malloc()
,
using the identically declared alloc()
function instead. Alloc
detects out-of-memory conditions and aborts, removing the need for error
checking on every call of malloc()
(and the temptation to skip
checking for out-of-memory).
As a convenience, SMARTALLOC supplies a compatible version of
alloc()
in the file alloc.c, with its definition in the file
alloc.h. This version of alloc()
is sensitive to the definition of
SMARTALLOC and cooperates with SMARTALLOC’s orphaned buffer detection.
In addition, when SMARTALLOC is defined and alloc()
detects an out
of memory condition, it takes advantage of the SMARTALLOC diagnostic
information to identify the file and line number of the call on
alloc()
that failed.
See also
Possible Next Steps
Go back to Smart Memory Allocation.
Go back to Developer Guide.