malloc.3c (2010 09)
m
malloc(3C) malloc(3C)
NAME
malloc(), alloca(), calloc(), free(), mallinfo(), mallopt(), memorymap(), realloc(), valloc() - main memory
allocator
SYNOPSIS
#include <stdlib.h>
void *malloc(size_t size);
void *calloc(size_t nelem, size_t elsize);
void free(void *ptr);
void *realloc(void *ptr, size_t size);
void *valloc(size_t size);
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);
char *calloc(unsigned nelem, unsigned elsize);
void free(char *ptr);
int mallopt(int cmd, int value);
char *realloc(char *ptr, unsigned size);
struct mallinfo mallinfo(void);
Remarks
The functionality in the old
malloc() package has been incorporated into malloc(). The library
(
/usr/lib/libmalloc.a
) corresponding to the -lmalloc linker option is now an empty library on
PA-RISC based systems only; it does not exist on Itanium-based systems. Makefiles that reference this
library on PA-RISC based systems will continue to work, but they will not work on Itanium-based sys-
tems.
Obsolescent Interfaces
memorymap() has been deprecated at HP-UX 11i Version 1 and is now obsolete. The
mal-
linfo() function is more useful for malloc statistics.
DESCRIPTION
The functions described here 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
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1