HP-UX Reference (11i v2 03/08) - 3 Library Functions A-M (vol 6)

m
malloc(3C) malloc(3C)
NAME
malloc(), free(), realloc(), calloc(), valloc(), mallopt(), mallinfo(), memorymap(), alloca() - main memory
allocator
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);
(Obsoleted)
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.
Obsolescent Interfaces
memorymap() has been deprecated at HP-UX 11i Version 1 and is now obsolete.
DESCRIPTION
The functions described in this manual entry provide a simple, general purpose memory allocation pack-
age:
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 ini-
tializes 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 mal-
loc() 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 alignments, 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
uninitialized.
free() Deallocates the space pointed to by ptr (a pointer to a block previously allocated
by malloc(), realloc(), calloc(),orvalloc()) and makes the space
available for further allocation. If ptr is a NULL pointer, no action occurs.
Section 3596 Hewlett-Packard Company 1 HP-UX 11i Version 2: August 2003