📄 malloc.3x
字号:
.\" SCCSID: @(#)malloc.3x 8.2 12/3/90.TH malloc 3x .SH Namemalloc, free, realloc, calloc, mallopt, mallinfo \- fast main memory allocator.SH Syntax.nf.B #include <malloc.h>.P.B char \(**malloc (size).B unsigned size;.PP.B void free (ptr).B char \(**ptr;.PP.B char \(**realloc (ptr, size).B char \(**ptr;.B unsigned size;.PP.B char \(**calloc (nelem, elsize).B unsigned nelem, elsize;.PP.B int mallopt (cmd, value).B int cmd, value;.PP.B struct mallinfo mallinfo (max).B int max;.SH Description.NXA "malloc subroutine (standard C)" "malloc subroutine (special library)".NXB "malloc subroutine (special library)" .NXB "memory" "allocating".NXR "free subroutine (special library)".NXR "realloc subroutine (special library)".NXR "calloc subroutine (special library)".NXR "mallopt subroutine".NXR "mallinfo subroutine"The.PN mallocand.PN freesubroutinesprovide a simple general-purpose memory allocation package,which runs considerably faster than the .MS malloc 3package.It is found in the library.PN malloc ,and is loaded if the option.PN \-lmallocis used with .MS cc 1or.MS ld 1 ..PPThe.PN mallocsubroutine returns a pointer to a block of at least.I size\^bytes suitably aligned for any use..PPThe argument to.PN freeis a pointer to a block previously allocated by.PN malloc .After.PN freeis performed,this space is made available for further allocation,and its contents have been destroyed. See .PN malloptbelow for a way to change this behavior..PPUndefined results will occur if the spaceassigned by.PN mallocis overrun or if some random number is handed to.PN free ..PPThe.PN reallocsubroutinechanges 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..PPThe.PN callocsubroutine allocates space for an array of.I nelemelements of size.I elsize.The space is initialized to zeros..PPThe .PN malloptsubroutineprovides for control over the allocation algorithm.The available values for .I cmdare:.TP .90iM_MXFASTSet .I maxfastto .I value .The algorithm allocates all blocks below the sizeof .I maxfastin large groups and then doles them out very quickly.The default value for.I maxfastis 0..TPM_NLBLKSSet .I numlblksto .I value .The above mentioned large groups each contain.I numlblksblocks. The.I numlblksmust be greater than 0.The default value for .I numlblksis 100..TPM_GRAINSet .I grainto .I value .The sizes of all blocks smaller than .I maxfastare considered to be rounded up to the nearest multiple of .I grain .The.I grainmust be greater than 0.The default value of .I grainis the smallest number of byteswhich will allow alignment of any data type.Valuewill be rounded up to a multiple of the defaultwhen.I grainis set..TPM_KEEPPreserve data in a freed block until the next.PN malloc ,.PN realloc ,or.PN calloc .This option is provided only for compatibility with the oldversion of .PN mallocand is not recommended..PPThese values are defined in the malloc.hheader file..PPThe.PN malloptsubroutine may be called repeatedly, but may not be called afterthe first small block is allocated..PPThe.PN mallinfosubroutineprovides information describing space usage.It returns the following structure:.NXR(e) "mallinfo subroutine" "structure returned".EX 0.ps 8struct mallinfo { int arena; /* total space in arena */ int ordblks; /* number of ordinary blocks */ int smblks; /* number of small blocks */ int hblkhd; /* space in holding block headers */ int hblks; /* number of holding blocks */ int usmblks; /* space in small blocks in use */ int fsmblks; /* space in free small blocks */ int uordblks; /* space in ordinary blocks in use */ int fordblks; /* space in free ordinary blocks */ int keepcost; /* space penalty if keep option */ /* is used */}.EE.PPThis structure is defined in the malloc.h header file..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 (special library)" "restrictions"This package usually uses more data space than.MS malloc 3 ..brThe code size is also bigger than .MS malloc 3 ..brNote that unlike .MS malloc 3 ,this package does not preservethe contents of a block when it is freed, unless the M_KEEPoption of.PN malloptis used..brUndocumented features of .MS malloc 3have not been duplicated..SH Return ValuesThe.PN malloc ,.PN realloc ,and.PN callocsubroutines return a NULLpointer if there is not enough available memory.When .PN reallocreturns NULL, the block pointed to by.I ptris left intact.If .PN malloptis called after any allocation or if.I cmdor.I valueare invalid, nonzero is returned.Otherwise, it returns zero..SH See Alsobrk(2), malloc(3).NXE "malloc subroutine (special library)" .NXE "memory" "allocating"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -