Skip to content

Commit 7d26cc9

Browse files
committed
Update README.md
1 parent d6d6bb2 commit 7d26cc9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a template class implementation of a memory pool allocator that is very
66
This library uses variadic templates for perfect argument forwarding and some other optimizations, and thus requires C++11 features. I may be willing to implement a C++98 version if somebody really needs it ([send me an email](mailto:[email protected]) if you are interested).
77

88
What is a Memory Pool
9-
-----------------------------------------
9+
-------------------------
1010
You would normally use `malloc` or `new` for dynamic memory management in C/C++. These functions are rather slow and have some memory overhead attached to them. This is fine if you make a few calls and ask for large chunks of memory, but if you need to store many small objects, the time and memory overhead may be unacceptable for high performance programs. This is where a memory pool comes in.
1111
A memory pool allocates memory in big chunks and splits the memory into smaller pieces. Every time you request memory, one of these small chunks is returned instead making a call to the OS or the heap allocator. You can only use a memory pool if you know the size of the objects beforehand, but if you do, a memory pool has a lot of advantages:
1212

@@ -20,6 +20,10 @@ A memory pool has just a few disadvantages:
2020
* Objects have a fixed size which must be known beforehand. This is usually not a problem and mostly the case if you need to allocate them in a bunch
2121
* You may need to fine tune them for your specific application. This is made very easy with the use of template classes.
2222

23+
When to Use
24+
-------------------------
25+
You should use a memory pool when you need to allocate many objects of the same size. This is usually the case when you implement common data structures like linked lists, binary search trees, hash tables with chaining and so on. Using a memory pool in these cases will increase performance by several folds and reduce wasted memory substantially.
26+
2327
C++ Compliance
2428
-------------------------
2529
MemoryPool is mostly compliant with the C++ Standard Library allocators. This means you can use it with `allocator_traits` ([see here] (http://www.cplusplus.com/reference/memory/allocator_traits/)) or just like you would use the `std::allocator` ([see here] (http://www.cplusplus.com/reference/memory/allocator/)). There are some differences though:

0 commit comments

Comments
 (0)