mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
o Reformat comment and correct typo.
This commit is contained in:
parent
1ed34e88aa
commit
ea31a9b09c
@ -12,42 +12,35 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The pool allocator is useful when you are going
|
* The pool allocator is useful when you are going to allocate
|
||||||
* to allocate lots of memory, use the memory for
|
* lots of memory, use the memory for a bit, and then free the
|
||||||
* a bit, and then free the memory in one go. A
|
* memory in one go. A surprising amount of code has this usage
|
||||||
* surprising amount of code has this usage
|
|
||||||
* profile.
|
* profile.
|
||||||
*
|
*
|
||||||
* You should think of the pool as an infinite,
|
* You should think of the pool as an infinite, contiguous chunk
|
||||||
* contigous chunk of memory. The front of this
|
* of memory. The front of this chunk of memory contains
|
||||||
* chunk of memory contains allocated objects, the
|
* allocated objects, the second half is free. pool_alloc grabs
|
||||||
* second half is free. pool_alloc grabs the next
|
* the next 'size' bytes from the free half, in effect moving it
|
||||||
* 'size' bytes from the free half, in effect
|
* into the allocated half. This operation is very efficient.
|
||||||
* moving it into the allocated half. This
|
|
||||||
* operation is very efficient.
|
|
||||||
*
|
*
|
||||||
* pool_free frees the allocated object *and* all
|
* pool_free frees the allocated object *and* all objects
|
||||||
* objects allocated after it. It is important to
|
* allocated after it. It is important to note this semantic
|
||||||
* note this semantic difference from malloc/free.
|
* difference from malloc/free. This is also extremely
|
||||||
* This is also extremely efficient, since a
|
* efficient, since a single pool_free can dispose of a large
|
||||||
* single pool_free can dispose of a large complex
|
* complex object.
|
||||||
* object.
|
|
||||||
*
|
*
|
||||||
* pool_destroy frees all allocated memory.
|
* pool_destroy frees all allocated memory.
|
||||||
*
|
*
|
||||||
* eg, If you are building a binary tree in your
|
* eg, If you are building a binary tree in your program, and
|
||||||
* program, and know that you are only ever going
|
* know that you are only ever going to insert into your tree,
|
||||||
* to insert into your tree, and not delete (eg,
|
* and not delete (eg, maintaining a symbol table for a
|
||||||
* maintaining a symbol table for a compiler).
|
* compiler). You can create yourself a pool, allocate the nodes
|
||||||
* You can create yourself a pool, allocate the
|
* from it, and when the tree becomes redundant call pool_destroy
|
||||||
* nodes from it, and when the tree becomes
|
* (no nasty iterating through the tree to free nodes).
|
||||||
* redundant call pool_destroy (no nasty iterating
|
|
||||||
* through the tree to free nodes).
|
|
||||||
*
|
*
|
||||||
* eg, On the other hand if you wanted to
|
* eg, On the other hand if you wanted to repeatedly insert and
|
||||||
* repeatedly insert and remove objects into the
|
* remove objects into the tree, you would be better off
|
||||||
* tree, you would be better off allocating the
|
* allocating the nodes from a free list; you cannot free a
|
||||||
* nodes from a free list; you cannot free a
|
|
||||||
* single arbitrary node with pool.
|
* single arbitrary node with pool.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user