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:

    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 (1743–1826)

    For my name and memory I leave it to men’s charitable speeches, and to foreign nations, and the next ages.
    Francis Bacon (1561–1626)

    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 good—like an amputated leg.
    John Paxton (1911–1985)