148349Scael.\" Copyright (c) 1980, 1991 Regents of the University of California. 248349Scael.\" All rights reserved. 320400Smckusick.\" 448349Scael.\" %sccs.include.redist.man% 520400Smckusick.\" 6*48897Ssellgren.\" @(#)malloc.3 6.6 (Berkeley) 05/01/91 748349Scael.\" 848349Scael.Dd 948349Scael.Dt MALLOC 3 1048349Scael.Os BSD 4 1148349Scael.Sh NAME 1248349Scael.Nm malloc , 1348349Scael.Nd general memory allocation function 1448349Scael.Sh SYNOPSIS 1548349Scael.Fd #include <stdlib.h> 1648349Scael.Ft void * 1748349Scael.Fn malloc "size_t size" 1848349Scael.Sh DESCRIPTION 1948349ScaelThe 2048349Scael.Fn malloc 2148349Scaelfunction allocates uninitialized space for an object whose 2248349Scaelsize is specified by 2348349Scael.Fa size . 2448349ScaelThe 2548349Scael.Fn malloc 2648349Scaelfunction maintains multiple lists of free blocks according to size, allocating 2748349Scaelspace from the appropriate list. 2848349Scael.Pp 2948349ScaelThe allocated space is 3048349Scaelsuitably aligned (after possible pointer 3148349Scaelcoercion) for storage of any type of object. If the space is of 3248349Scael.Em pagesize 3328178Skarelsor larger, the memory returned will be page-aligned. 3448349Scael.Sh RETURN VALUES 3548349ScaelThe 3648349Scael.Fn malloc 3748349Scaelfunction returns 3848349Scaela pointer to the allocated space if successful; otherwise 3948349Scaela null pointer is returned. 4048349Scael.Sh SEE ALSO 4148349Scael.Xr brk 2 , 42*48897Ssellgren.Xr pagesize 2 , 4348349Scael.Xr free 3 , 4448349Scael.Xr calloc 3 , 4548349Scael.Xr alloca 3 , 4648349Scael.Xr realloc 3 , 4748349Scael.Xr memory 3 4848349Scael.Sh STANDARDS 4948349ScaelThe 5048349Scael.Fn malloc 5148349Scaelfunction conforms to 5248349Scael.St -ansiC . 5348349Scael.Sh BUGS 5428178SkarelsThe current implementation of 5548349Scael.Xr malloc 5628178Skarelsdoes not always fail gracefully when system 5728178Skarelsmemory limits are approached. 5828178SkarelsIt may fail to allocate memory when larger free blocks could be broken 5928178Skarelsup, or when limits are exceeded because the size is rounded up. 6028178SkarelsIt is optimized for sizes that are powers of two. 61