BookRags.com Literature Guides Literature Guides Criticism/Essays Criticism/Essays Biographies Biographies My Bibliography Periodic Table U.S. Presidents Shakespeare Sonnet Shake-Up
Research Anything:        
History | Encyclopedias | Films | News | Create a Bibliography | More... Login | Register | Help
Not What You Meant?  There are 37 definitions for Pool.

Memory pool

Print-Friendly
About 1 pages (404 words)

Bookmark and Share

Memory pools allow dynamic memory allocation comparable to malloc or C++'s operator new. As those implementations suffer from fragmentation because of variable block sizes, it can be impossible to use them in a real time system due to performance. A more efficient solution is preallocating a number of memory blocks with the same size called the memory pool. The application can allocate, access, and free blocks represented by handles at runtime.

Contents

Sample memory pool implementation

A simple memory pool module can allocate for example 3 pools at compile time with block sizes optimized for the application, which deploys the module. The application can allocate, access and free memory with the following interface:

MemPoolHandle allocateMemory(size_t bytes);

To allocate memory from the pools. The function will determine the pool, where the required block fits in. If all blocks of that pool are already reserved, the function tries to find one in the next bigger pool(s). An allocated memory block is represented with a handle.

void * getPointer(MemPoolHandle h);

To get an access pointer to the allocated memory .

void freeMemory(MemPoolHandle h);

To free the formerly allocated memory block.

typedef signed int MemPoolHandle;

The handle can for example be implemented with an unsigned int. The module can interpret the handle internally by dividing it into pool index, memory block index and a version. The pool and memory block index allow fast access to the corresponding block with the handle, while the version, which is incremented at each new allocation, allows detection of handles whose memory block is already freed (caused by handles retained too long).

Memory pool vs malloc

Memory pools allow memory allocation with constant execution time (no fragmentation). The memory release for thousands of objects in a pool is just one operation, not one by one if malloc is used to allocate memory for each object. Third, memory pools can be grouped in hierarchical tree structures, which is suitable for special programming structures like loops and recursions. On the other hand, they need to be tuned for the application which deploys them.

See also

References

External links

View More Summaries on Memory pool
 
Copyrights
Memory pool from Wíkipedia. ©2006 by Wíkipedia. Licensed under the GNU Free Documentation License. View a list of authors or edit this article.

Article Navigation
Join BookRagslearn moreJoin BookRags


About BookRags | Customer Service | Report an Error | Terms of Use | Privacy Policy