📄 malloc.3
字号:
.\" SCCSID: @(#)malloc.3 3.1 11/24/87.TH malloc 3 RISC.SH Namemalloc, free, realloc, calloc, alloca \- memory allocator.SH Syntax.nf.B char *malloc(size).B unsigned size;.PP.B free(ptr).B void *ptr;.PP.B char *realloc(ptr, size).B void *ptr;.B unsigned size;.PP.B char *calloc(nelem, elsize).B unsigned nelem, elsize;.PP.B char *alloca(size).B int size;.fi.SH Description.NXR "malloc subroutine (standard C)".NXR "free subroutine (standard C)".NXR "realloc subroutine (standard C)".NXR "calloc subroutine (standard C)".NXR "alloca subroutine".NXA "memory" "shared memory".NXR "memory" "allocating"The.PN mallocand.PN freesubroutinesprovide a simple general-purpose memory allocation package.The.PN mallocsubroutinereturns a pointer to a block of at least.I sizebytes beginning on a word boundary..PPThe argument to.PN freeis a pointer to a block previously allocated by.PN malloc .This space is made available for further allocation,but its contents are left undisturbed..PPNeedless to say, grave disorder will result if the space assigned by.PN mallocis overrun or if some random number is handed to.PN free ..PPThe.PN mallocsubroutinemaintains multiple lists of free blocks according to size,allocating space from the appropriate list.It calls.PN sbrkto get more memory from the system when there is nosuitable space already free.For further information, see .MS brk 2 ..PPThe.PN reallocsubroutine changes 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 thelesser of the new and old sizes..PPIn order to be compatible with older versions,.PN reallocalso works if.I ptrpoints to a block freed since the last call of.PN malloc ,.PN realloc ,or.PN calloc .Sequences of.PN free ,.PN malloc, and.PN reallocwere previously used to attempt storage compaction.This procedure is no longer recommended..PPThe.PN callocsubroutine allocates space for an array of.I nelemelements of size.I elsize.The space is initialized to zeros..PP.\"VAX.\"The.\".PN alloca.\"subroutine allocates .\".I size.\"bytes of space in the stack frame of the caller..\"This temporary space is automatically freed on.\"return.The.PN allocasubroutine allocates .I sizebytes of space associated with the stack frame of the caller.This temporary space is available for reuse when the caller returns.On MIPS machines, calling.PN alloca (0)reclaims all available storage. On VAX machines, the space isautomatically freed on return..PPEach of the allocation routines returns a pointerto space suitably aligned (after possible pointer coercion)for storage of any type of object..SH Restrictions.NXR "malloc subroutine (standard C)" "restricted"When.PN reallocreturns 0, the block pointed to by.I ptrmay be destroyed..PPCurrently, the allocator is unsuitable for direct use in a largevirtual environment where many small blocks are kept, since it keeps all allocated and freed blocks on a circularlist.Just before more memory is allocated,all allocated and freed blocks are referenced..PP.\"VAX.\"The.\".PN alloca.\"subroutine is machine dependent.Because the.PN allocasubroutine is machine dependent,its use should be avoided..SH DiagnosticsThe.PN malloc ,.PN realloc ,and.PN callocsubroutinesreturn a nullpointer (0) if there is no available memory or if the arenahas been detectably corrupted by storing outside the bounds of a block.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -