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:
- 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.
- Get an access pointer to the allocated memory.
- Free the formerly allocated memory block.
- 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).
Read more about this topic: Memory Pool
Famous quotes containing the words sample, memory and/or pool:
“The present war having so long cut off all communication with Great-Britain, we are not able to make a fair estimate of the state of science in that country. The spirit in which she wages war is the only sample before our eyes, and that does not seem the legitimate offspring either of science or of civilization.”
—Thomas Jefferson (17431826)
“A man of sense, though born without wit, often lives to have wit. His memory treasures up ideas and reflections; he compares them with new occurrences, and strikes out new lights from the collision. The consequence is sometimes bons mots, and sometimes apothegms.”
—Horace Walpole (17171797)
“As every pool reflects the image of the sun, so every thought and thing restores us an image and creature of the supreme Good. The universe is perforated by a million channels for his activity. All things mount and mount.”
—Ralph Waldo Emerson (18031882)