#include <lclib.h> char *sbrk(size_t bytes);
sbrk
allocates a block of memory of the size specified by bytes
.
The block is suballocated from an area allocated at program initialization.
The size of this area is determined by the initial value of the external
variable _mneed
; if this variable is not set, a default area of 100K is
allocated the first time sbrk
is called.
sbrk
returns the address of the first character of the block of memory.
The block is suitably aligned for storage of any type of data.
sbrk
is an inflexible mechanism for memory allocation. It has no
provision for increasing the size of the sbrk
-managed area (even if
free memory is available for this purpose). Using malloc
, which
does not have this limitation, is recommended for memory allocation wherever
possible.
Memory allocated with sbrk
cannot be returned to the operating system
(except implicitly at program termination).
sbrk
is called or if 0 bytes
of memory are requested, sbrk
returns (char *)-1
.
sbrk
is compatible with some versions of traditional UNIX C compilers.
It is not well suited to the 370 environment; therefore, use malloc
in its place whenever possible.
sbrk
resides above the 16-megabyte line for programs that run in 31-bit addressing
mode.
#include <lclib.h> #include <stdio.h> int _mneed = 1024; /* Define default size of sbrk area. */ main() { int n; char *stg; for(n = 1; ; ++n){ stg = sbrk(80); if (stg == (char *) -1) break; } printf("%d 80-byte blocks could be allocated by sbrk.n", n); puts("To change the amount available to sbrk, pass " "the runtime option =/<n>,"); puts("replacing <n> with the size of the sbrk area."); }
malloc
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.