⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pool_alloc.3

📁 Rsync 3.0.5 source code
💻 3
字号:
.ds d \-\^\-.ds o \fR[\fP.ds c \fR]\fP.ds | \fR|\fP.de D\\.B \*d\\$1...de DI\\.BI \*d\\$1 \\$2...de DR\\.BR \*d\\$1 \\$2...de Di\\.BI \*d\\$1 " \\$2"...de Db\\.B \*d\\$1 " \\$2"...de Df\\.B \*d\*ono\*c\\$1...de SeeSee \fB\\$1\fP for details....de SeeInSee \fB\\$1\fP in \fB\\$2\fP for details....TH POOL_ALLOC 3.SH NAMEpool_alloc, pool_free, pool_free_old, pool_talloc, pool_tfree, pool_create, pool_destroy, pool_boundary\- Allocate and free memory in managed allocation pools..SH SYNOPSIS.B #include "pool_alloc.h"\fBstruct alloc_pool *pool_create(size_t \fIsize\fB, size_t \fIquantum\fB, void (*\fIbomb\fB)(char *), int \fIflags\fB);\fBvoid pool_destroy(struct alloc_pool *\fIpool\fB);\fBvoid *pool_alloc(struct alloc_pool *\fIpool\fB, size_t \fIsize\fB, char *\fImsg\fB);\fBvoid pool_free(struct alloc_pool *\fIpool\fB, size_t \fIsize\fB, void *\fIaddr\fB);\fBvoid pool_free_old(struct alloc_pool *\fIpool\fB, void *\fIaddr\fB);\fBvoid *pool_talloc(struct alloc_pool *\fIpool\fB, \fItype\fB), int \fIcount\fB, char *\fImsg\fB);\fBvoid pool_tfree(struct alloc_pool *\fIpool\fB, \fItype\fB, int \fIcount\fB, void *\fIaddr\fB);\fBvoid pool_boundary(struct alloc_pool *\fIpool\fB, sise_t \fIsize\fB);.SH DESCRIPTION.PThe pool allocation routines use.B malloc()for underlying memory management.What allocation pools do is cause memory within a given poolto be allocated in large contiguous blocks(called extents) that will be reusable when freed.  Unlike.BR malloc() ,the allocations are not managed individually.Instead, each extent tracks the total free memory within theextent.  Each extent can either be used to allocate memoryor to manage the freeing of memory within that extent.When an extent has less free memory than a givenallocation request, the current extent ceases to be usedfor allocation.  See also the.B pool_boundary()function..PThis form of memory management is suited to large numbers of smallrelated allocations that are held for a whileand then freed as a group.Because theunderlying allocations are done in large contiguous extents,when an extent is freed, it can release a large enoughcontiguous block of memory to allow the memory to be returnedto the OS for use by whatever program needs it.You can allocate from one or more memory pools and/or.B malloc()all at the same time without interfering with how pools work..P.B pool_create()Creates an allocation pool for subsequent calls to the poolallocation functions.When an extent is created for allocations it will be.I size bytes.Allocations from the pool have their sizes rounded up to amultiple of.I quantumbytes in length.Specifying.B 0for.I quantumwill produce a quantum that should meet maximal alignmenton most platforms.If.B POOL_QALIGNis set in the.IR flags ,allocations will be aligned to addresses that are amultiple of.IR quantum .If.B POOL_CLEARis set in the.IR flags ,all allocations from the pool will be initialized to zeros.You may specify a.B NULLfor the.I bombfunction pointer if you don't wish to use it.  (See the.B pool_alloc()function for how it is used.).P.B pool_destroy()destroys an allocation.I pooland frees all its associated memory..P.B pool_alloc()allocates.I sizebytes from the specified.IR pool .If.I sizeis.BR 0 ,.I quantumbytes will be allocated.If the pool has been created with.BR POOL_QALIGN ,every chunk of memory that is returned will be suitably aligned.You can use this with the default.I quantumsize to ensure that all memory can store a variable of any type.If the requested memory cannot be allocated, the.I bomb()function will be called with.I msgas its sole argument (if the function was defined at the timethe pool was created), and then a.B NULLaddress is returned (assuming that the bomb function didn't exit)..P.B pool_free()frees.I sizebytes pointed to by an.I addrthat was previously allocated in the specified.IR pool .If.I sizeis.BR 0 ,.I quantumbytes will be freed.The memory freed within an extent will not be reusable untilall of the memory in that extent has been freed with oneexception: the most recent pool allocation may be freed backinto the pool prior to making any further allocations.If enough free calls are made to indicate that an extent has noremaining allocated objects (as computed by the total freed size foran extent), its memory will be completely freed back to the system.If.I addris.BR 0 ,no memory will be freed, but subsequent allocations will comefrom a new extent..P.B pool_free_old()takes a boundary.I addrvalue that was returned by.B pool_boundary()and frees up any extents in the.I poolthat have data allocated from that point backward in time.NOTE: you must NOT mix calls to both.B pool_freeand.B pool_free_oldon the same pool!.P.B pool_boundary()asks for a boundary value that can be sent to .B pool_free_old()at a later time to free up all memory allocated prior to a particularmoment in time.If the extent that holds the boundary point has allocations from after theboundary point, it will not be freed until a future.B pool_free_old()call encompasses the entirety of the extent's data.If.I lenis non-zero, the call will also check if the active extent has at leastthat much free memory available in it, and if not, it will mark theextent as inactive, forcing a new extent to be used for future allocations.(You can specify -1 for.I lenif you want to force a new extent to start.).P.B pool_talloc()is a macro that takes a.I typeand a.I countinstead of a.IR size .It casts the return value to the correct pointer type..P.B pool_tfreeis a macro that calls.B pool_freeon memory that was allocated by.BR pool_talloc() ..SH RETURN VALUE.B pool_create()returns a pointer to.BR "struct alloc_pool" ..P.B pool_alloc()and.B pool_talloc()return pointers to the allocated memory,or NULL if the request fails.The return type of.B pool_alloc()will normally require casting to the desired type but.B pool_talloc()will returns a pointer of the requested.IR type ..P.B pool_boundary()returns a pointer that should only be used in a call to.BR pool_free_old() ..P.BR pool_free() ,.BR pool_free_old() ,.B pool_tfree()and.B pool_destroy()return no value..SH SEE ALSO.nfmalloc(3).SH AUTHORpool_alloc was created by J.W. Schultz of Pegasystems Technologies..SH BUGS AND ISSUES

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -