📄 malloc.3
字号:
.\" Copyright (c) 1980 Regents of the University of California..\" All rights reserved. The Berkeley software License Agreement.\" specifies the terms and conditions for redistribution..\".\" @(#)malloc.3 6.3 (Berkeley) 5/14/86.\".TH MALLOC 3 "May 14, 1986".UC 4.SH NAMEmalloc, free, realloc, calloc, alloca \- memory allocator.SH SYNOPSIS.nf.ft B#include <sys/types.h>#include <stdlib.h>#include <alloca.h>void *malloc(size_t \fIsize\fP)void free(void *\fIptr\fP)void *realloc(void *\fIptr\fP, size_t \fIsize\fP)void *calloc(size_t \fInelem\fP, size_t \fIelsize\fP)void *alloca(size_t \fIsize\fP).ft R.fi.SH DESCRIPTION.B Mallocand.B freeprovide a general-purpose memory allocation package..B Mallocreturns a pointer to a block of at least.I sizebytes beginning on a word boundary..PPThe argument to.B freeis a pointer to a block previously allocated by.BR malloc ;this space is made available for further allocation,but its contents are left undisturbed.A call with a null.I ptris legal and does nothing..PPNeedless to say, grave disorder will result if the space assigned by.B mallocis overrun or if some random number is handed to.BR free ..PP.B Mallocmaintains multiple lists of free blocks according to size,allocating space from the appropriate list.It calls.B sbrk(see.BR brk (2))to get more memory from the system when there is nosuitable space already free..PP.B Reallocchanges the size of the block pointed to by.I ptrto.I sizebytes and returns a pointer to the (possibly moved) block.The contents will be unchanged up to the lesser of the new and old sizes.A call with a null.I ptris legal and has the same result as.BI malloc( size )\fR..PP.B Callocallocates space for an array of.I nelemelements of size.I elsize.The space is initialized to zeros..PP.B Allocaallocates .I sizebytes of space in the stack frame of the caller.This temporary space is automatically freed onreturn..PPEach of the allocation routines returns a pointerto space suitably aligned (after possible pointer coercion)for storage of any type of object..SH SEE ALSO.BR brk (2)..SH DIAGNOSTICS.BR Malloc ,.BR reallocand.B callocreturn a null pointer if there is no available memory or if the arenahas been detectably corrupted by storing outside the bounds of a block..SH NOTESOther implementations of.BR malloc ,.BR reallocor.BR callocmay return a null pointer if the size of the requested block is zero. Thisimplementation will always return a zero length block at a unique address,but you should keep in mind that a null return is possible if the programis run to another system and that this should not be mistakenly seen asan error..SH BUGSWhen.B reallocreturns a null pointer, the block pointed to by.I ptrmay be destroyed..PP.B Allocais machine dependent; its use is discouraged.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -