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:
“As a rule they will refuse even to sample a foreign dish, they regard such things as garlic and olive oil with disgust, life is unliveable to them unless they have tea and puddings.”
—George Orwell (19031950)
“With memory set smarting like a reopened wound, a mans past is not simply a dead history, an outworn preparation of the present: it is not a repented error shaken loose from the life: it is a still quivering part of himself, bringing shudders and bitter flavours and the tinglings of a merited shame.”
—George Eliot [Mary Ann (or Marian)
“I caught a blackjack right behind my ear. A black pool opened up at my feet. I dived in. It had no bottom. I felt pretty goodlike an amputated leg.”
—John Paxton (19111985)