Memory Pool - Sample Memory Pool Implementation

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:

    All that a city will ever allow you is an angle on it—an oblique, indirect sample of what it contains, or what passes through it; a point of view.
    Peter Conrad (b. 1948)

    What has kept the world safe from the bomb since 1945 has not been deterrence, in the sense of fear of specific weapons, so much as it’s been memory. The memory of what happened at Hiroshima.
    John Hersey (b. 1914)

    I’ th’ world’s volume
    Our Britain seems as of it, but not in’ t;
    In a great pool a swan’s nest.
    William Shakespeare (1564–1616)