diff options
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 57 | 
1 files changed, 39 insertions, 18 deletions
| diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index e7c237c63a..c9c87cf420 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -33,31 +33,30 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
| 34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. | 
| 35 | .\" | 35 | .\" | 
| 36 | .\" $OpenBSD: malloc.3,v 1.15 1999/06/29 18:36:21 aaron Exp $ | 36 | .\" $OpenBSD: malloc.3,v 1.16 1999/11/09 22:12:36 aaron Exp $ | 
| 37 | .\" | 37 | .\" | 
| 38 | .Dd August 27, 1996 | 38 | .Dd August 27, 1996 | 
| 39 | .Dt MALLOC 3 | 39 | .Dt MALLOC 3 | 
| 40 | .Os | 40 | .Os | 
| 41 | .Sh NAME | 41 | .Sh NAME | 
| 42 | .Nm malloc , | 42 | .Nm malloc , | 
| 43 | .Nd general memory allocation function | 43 | .Nm calloc , | 
| 44 | .Pp | 44 | .Nm realloc , | 
| 45 | .Nm free , | 45 | .Nm free , | 
| 46 | .Nm cfree | 46 | .Nm cfree | 
| 47 | .Nd free up memory allocated with malloc, calloc or realloc | 47 | .Nd memory allocation and deallocation | 
| 48 | .Pp | ||
| 49 | .Nm realloc | ||
| 50 | .Nd reallocation of memory function | ||
| 51 | .Sh SYNOPSIS | 48 | .Sh SYNOPSIS | 
| 52 | .Fd #include <stdlib.h> | 49 | .Fd #include <stdlib.h> | 
| 53 | .Ft void * | 50 | .Ft void * | 
| 54 | .Fn malloc "size_t size" | 51 | .Fn malloc "size_t size" | 
| 52 | .Ft void * | ||
| 53 | .Fn calloc "size_t nmemb" "size_t size" | ||
| 54 | .Ft void * | ||
| 55 | .Fn realloc "void *ptr" "size_t size" | ||
| 55 | .Ft void | 56 | .Ft void | 
| 56 | .Fn free "void *ptr" | 57 | .Fn free "void *ptr" | 
| 57 | .Ft void | 58 | .Ft void | 
| 58 | .Fn cfree "void *ptr" | 59 | .Fn cfree "void *ptr" | 
| 59 | .Ft void * | ||
| 60 | .Fn realloc "void *ptr" "size_t size" | ||
| 61 | .Ft char * | 60 | .Ft char * | 
| 62 | .Va malloc_options | 61 | .Va malloc_options | 
| 63 | .Sh DESCRIPTION | 62 | .Sh DESCRIPTION | 
| @@ -80,6 +79,14 @@ or larger, the memory returned will be page-aligned. | |||
| 80 | Allocation of a zero size object returns a pointer to a zero size object. | 79 | Allocation of a zero size object returns a pointer to a zero size object. | 
| 81 | .Pp | 80 | .Pp | 
| 82 | The | 81 | The | 
| 82 | .Fn calloc | ||
| 83 | function allocates space for an array of | ||
| 84 | .Fa nmemb | ||
| 85 | objects, each of whose size is | ||
| 86 | .Fa size . | ||
| 87 | The space is initialized to all bits zero. | ||
| 88 | .Pp | ||
| 89 | The | ||
| 83 | .Fn free | 90 | .Fn free | 
| 84 | function causes the space pointed to by | 91 | function causes the space pointed to by | 
| 85 | .Fa ptr | 92 | .Fa ptr | 
| @@ -231,13 +238,17 @@ See above. | |||
| 231 | .Sh RETURN VALUES | 238 | .Sh RETURN VALUES | 
| 232 | The | 239 | The | 
| 233 | .Fn malloc | 240 | .Fn malloc | 
| 234 | function returns | 241 | and | 
| 242 | .Fn calloc | ||
| 243 | functions return | ||
| 235 | a pointer to the allocated space if successful; otherwise | 244 | a pointer to the allocated space if successful; otherwise | 
| 236 | a null pointer is returned. | 245 | a null pointer is returned. | 
| 237 | .Pp | 246 | .Pp | 
| 238 | The | 247 | The | 
| 239 | .Fn free | 248 | .Fn free | 
| 240 | function returns no value. | 249 | and | 
| 250 | .Fn cfree | ||
| 251 | functions return no value. | ||
| 241 | .Pp | 252 | .Pp | 
| 242 | The | 253 | The | 
| 243 | .Fn realloc | 254 | .Fn realloc | 
| @@ -286,14 +297,16 @@ A pointer to a free chunk is attempted freed again. | |||
| 286 | .Pp | 297 | .Pp | 
| 287 | ``junk pointer, too high to make sense.'' | 298 | ``junk pointer, too high to make sense.'' | 
| 288 | The pointer doesn't make sense. It's above the area of memory that | 299 | The pointer doesn't make sense. It's above the area of memory that | 
| 289 | malloc knows something about. | 300 | .Fn malloc | 
| 301 | knows something about. | ||
| 290 | This could be a pointer from some | 302 | This could be a pointer from some | 
| 291 | .Xr mmap 2 'ed | 303 | .Xr mmap 2 'ed | 
| 292 | memory. | 304 | memory. | 
| 293 | .Pp | 305 | .Pp | 
| 294 | ``junk pointer, too low to make sense.'' | 306 | ``junk pointer, too low to make sense.'' | 
| 295 | The pointer doesn't make sense. It's below the area of memory that | 307 | The pointer doesn't make sense. It's below the area of memory that | 
| 296 | malloc knows something about. | 308 | .Fn malloc | 
| 309 | knows something about. | ||
| 297 | This pointer probably came from your data or bss segments. | 310 | This pointer probably came from your data or bss segments. | 
| 298 | .Pp | 311 | .Pp | 
| 299 | ``malloc() has never been called.'' | 312 | ``malloc() has never been called.'' | 
| @@ -304,7 +317,9 @@ realloc'ed. | |||
| 304 | The pointer passed to free or realloc has been modified. | 317 | The pointer passed to free or realloc has been modified. | 
| 305 | .Pp | 318 | .Pp | 
| 306 | ``pointer to wrong page.'' | 319 | ``pointer to wrong page.'' | 
| 307 | The pointer that malloc is trying to free is not pointing to | 320 | The pointer that | 
| 321 | .Fn malloc | ||
| 322 | is trying to free is not pointing to | ||
| 308 | a sensible page. | 323 | a sensible page. | 
| 309 | .Pp | 324 | .Pp | 
| 310 | ``recursive call.'' | 325 | ``recursive call.'' | 
| @@ -338,14 +353,20 @@ The | |||
| 338 | function conforms to | 353 | function conforms to | 
| 339 | .St -ansiC . | 354 | .St -ansiC . | 
| 340 | .Sh HISTORY | 355 | .Sh HISTORY | 
| 341 | The present implementation of malloc started out as a filesystem on a drum | 356 | The present implementation of | 
| 342 | attached to a 20bit binary challenged computer built with discrete germanium | 357 | .Fn malloc | 
| 358 | started out as a filesystem on a drum | ||
| 359 | attached to a 20-bit binary challenged computer built with discrete germanium | ||
| 343 | transistors, and it has since graduated to handle primary storage rather than | 360 | transistors, and it has since graduated to handle primary storage rather than | 
| 344 | secondary. | 361 | secondary. | 
| 345 | .Pp | 362 | .Pp | 
| 346 | The main difference from other malloc implementations are believed to be that | 363 | The main difference from other | 
| 364 | .Fn malloc | ||
| 365 | implementations are believed to be that | ||
| 347 | the free pages are not accessed until allocated. | 366 | the free pages are not accessed until allocated. | 
| 348 | Most malloc implementations will store a data structure containing a, | 367 | Most | 
| 368 | .Fn malloc | ||
| 369 | implementations will store a data structure containing a, | ||
| 349 | possibly double-, linked list in the free chunks of memory, used to tie | 370 | possibly double-, linked list in the free chunks of memory, used to tie | 
| 350 | all the free memory together. | 371 | all the free memory together. | 
| 351 | That is a quite suboptimal thing to do. | 372 | That is a quite suboptimal thing to do. | 
