'\" te .\" Copyright 1989 AT&T. Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH mapmalloc 3MALLOC "20 Feb 2004" "SunOS 5.11" "Memory Allocation Library Functions" .SH NAME mapmalloc \- memory allocator .SH SYNOPSIS .LP .nf \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lmapmalloc\fR [ \fIlibrary\fR ... ] #include \fBvoid *\fR\fBmalloc\fR(\fBsize_t\fR \fIsize\fR); .fi .LP .nf \fBvoid *\fR\fBcalloc\fR(\fBsize_t\fR \fInelem\fR, \fBsize_t\fR \fIelsize\fR); .fi .LP .nf \fBvoid\fR \fBfree\fR(\fBvoid *\fR \fIptr\fR); .fi .LP .nf \fBvoid *\fR\fBrealloc\fR(\fBvoid *\fR\fIptr\fR, \fBsize_t\fR \fIsize\fR); .fi .SH DESCRIPTION .sp .LP The collection of \fBmalloc\fR functions in this library use \fBmmap\fR(2) instead of \fBsbrk\fR(2) for acquiring new heap space. The functions in this library are intended to be used only if necessary, when applications must call \fBsbrk()\fR, but need to call other library routines that might call \fBmalloc\fR. The algorithms used by these functions are not sophisticated. There is no reclaiming of memory. .sp .LP The \fBmalloc()\fR and \fBfree()\fR functions provide a simple general-purpose memory allocation package. .sp .LP The \fBmalloc()\fR function returns a pointer to a block of at least \fIsize\fR bytes suitably aligned for any use. .sp .LP The argument to \fBfree()\fR is a pointer to a block previously allocated by \fBmalloc()\fR, \fBcalloc()\fR or \fBrealloc()\fR. If \fIptr\fR is a \fINULL\fR pointer, no action occurs. .sp .LP Undefined results will occur if the space assigned by \fBmalloc()\fR is overrun or if some random number is handed to \fBfree()\fR. .sp .LP The \fBcalloc()\fR function allocates space for an array of \fInelem\fR elements of size \fIelsize\fR. The space is initialized to zeros. .sp .LP The \fBrealloc()\fR function changes the size of the block pointed to by \fIptr\fR to \fIsize\fR bytes and returns a pointer to the (possibly moved) block. The contents will be unchanged up to the lesser of the new and old sizes. If the new size of the block requires movement of the block, the space for the previous instantiation of the block is freed. If the new size is larger, the contents of the newly allocated portion of the block are unspecified. If \fIptr\fR is \fINULL\fR, \fBrealloc()\fR behaves like \fBmalloc()\fR for the specified size. If \fIsize\fR is 0 and \fIptr\fR is not a null pointer, the space pointed to is freed. .sp .LP Each of the allocation functions returns a pointer to space suitably aligned (after possible pointer coercion) for storage of any type of object. .sp .LP The \fBmalloc()\fR and \fBrealloc()\fR functions will fail if there is not enough available memory. .sp .LP Entry points for \fBmalloc_debug()\fR, \fBmallocmap()\fR, \fBmallopt()\fR, \fBmallinfo()\fR, \fBmemalign()\fR, and \fBvalloc()\fR are empty routines, and are provided only to protect the user from mixing \fBmalloc()\fR functions from different implementations. .SH RETURN VALUES .sp .LP If there is no available memory, \fBmalloc()\fR, \fBrealloc()\fR, and \fBcalloc()\fR return a null pointer. When \fBrealloc()\fR returns \fINULL\fR, the block pointed to by \fIptr\fR is left intact. If \fIsize\fR, \fInelem\fR, or \fIelsize\fR is 0, a unique pointer to the arena is returned. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ MT-LevelSafe .TE .SH SEE ALSO .sp .LP \fBbrk\fR(2), \fBgetrlimit\fR(2), \fBmmap\fR(2), \fBrealloc\fR(3C), \fBmalloc\fR(3MALLOC), \fBattributes\fR(5)