HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
m
malloc(3C) malloc(3C)
NAME
malloc(), free(), realloc(), calloc(), valloc(), mallopt(), mallinfo(), memorymap(), alloca() - main memory allo-
cator
SYNOPSIS
#include <stdlib.h>
void *malloc(size_t size);
void *calloc(size_t nelem, size_t elsize);
void *realloc(void *ptr, size_t size);
void *valloc(size_t size);
void free(void *ptr);
void memorymap(int show_stats);
alloca
#include <alloca.h>
void *alloca(size_t size);
SYSTEM V SYNOPSIS
#include <malloc.h>
char *malloc(unsigned size);
void free(char *ptr);
char *realloc(char *ptr, unsigned size);
char *calloc(unsigned nelem, unsigned elsize);
int mallopt(int cmd, int value);
struct mallinfo mallinfo(void);
Remarks
The functionality in the old malloc(3X) package has been incorporated into malloc(3C). The library
(
/usr/lib/libmalloc.a
) corresponding to the -lmalloc linker option is now an empty library.
Makefiles that reference this library will continue to work.
DESCRIPTION
The functions described in this manual entry provide a simple, general purpose memory allocation package:
malloc() Allocates space for a block of at least size bytes, but does not initialize the space.
calloc() Allocates space for an array of nelem elements, each of size elsize bytes, and initial-
izes the space to zeros. Actual amount of space allocated will be at least nelem *
elsize bytes.
realloc() Changes the size of the block pointed to by ptr to size bytes and returns a pointer to
the (possibly moved) block. Existing contents are unchanged up to the lesser of the
new and old sizes. If ptr is a NULL pointer, realloc() behaves like malloc()
for the specified size. If size is zero and ptr is not a NULL pointer, the object it
points to is freed and NULL is returned. realloc() of blocks with special align-
ments, such as those created by valloc(), is not supported.
valloc() Allocates space for a block of at least size bytes starting on a boundary aligned to a
multiple of the value returned by sysconf(__SC_PAGESIZE). This space is unin-
itialized.
free() Deallocates the space pointed to by ptr (a pointer to a block previously allocated by
malloc(), realloc(), calloc(),orvalloc()) and makes the space avail-
able for further allocation. If ptr is a NULL pointer, no action occurs.
mallopt() Provides for control over the allocation algorithm and other options in the
malloc(3C) package. The available values for cmd are:
HP-UX Release 11i: December 2000 − 1 − Section 3−−507
___
___