Chapter Contents |
Previous |
Next |
Function Categories |
The
standard library provides several different levels of memory allocation, providing
varying levels of portability, efficiency, and convenience. The
malloc
family of functions (
calloc
,
malloc
,
free
,
and
realloc
) conforms to the ISO/ANSI standard
and is therefore the most portable (and usually the most convenient) technique
for memory allocation. The
pool
family
of functions (
pool
,
palloc
,
pfree
, and
pdel
) is not portable but is more efficient for many applications.
Finally, the
sbrk
function provides compatibility
with traditional UNIX low-level memory management but is inflexible because
the maximum amount of memory that can be allocated is fixed independently
of the size of the region or virtual machine. All of the memory allocation
functions return a pointer of type
void *
that is guaranteed to be properly aligned to store any object.
All of these interfaces, except
sbrk
, use the operating system's standard memory allocation technique
(GETMAIN under OS/390, DMSFREE under CMS, or CMSSTOR under bimodal CMS) to
allocate memory blocks. This means that blocks allocated by the C language
may be interspersed with blocks allocated by the operating system or by other
programs. It also means that the C program is always able to allocate memory
up to the limits imposed by the region or virtual machine size.
Under OS/390, all SAS/C memory allocation (except when
the program invokes the GETMAIN SVC directly) is task related. Thus, it is
not valid to use
malloc
to allocate a block
of memory under one TCB and free it under another. Even if the two tasks
share all OS/390 subpools, this error will cause memory management chains
to become erroneously linked, which will eventually cause a memory management
ABEND in one or more of the involved tasks.
Even the SAS/C pool allocation functions, such as
palloc
, do not allow memory allocation to be
managed across task boundaries.
palloc
calls
malloc
to extend a pool if necessary;
therefore, it may corrupt memory chains if used under the wrong task. Additionally,
the code generated by
palloc
and
pfree
does no synchronization, which means that
simultaneous use on the same pool in several tasks could cause the same element
to be allocated twice, or lost from the memory chains.
The memory allocation functions are
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.