HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)

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>
void *malloc(size_t size);
void free(void *ptr);
void *realloc(void *ptr, size_t size);
void *calloc(size_t nelem, size_t 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.
Obsolescent Interfaces
The
memorymap() function has been deprecated as of HP-UX 11.11, and will be obsolete at the next
release of HP-UX.
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.
Section 3542 Hewlett-Packard Company 1 HP-UX 11i Version 1: September 2005