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)

    I regard a love for poetry as one of the most needful and helpful elements in the life- outfit of a human being. It was the greatest of blessings to me, in the long days of toil to which I was shut in much earlier than most young girls are, that the poetry I held in my memory breathed its enchanted atmosphere through me and around me, and touched even dull drudgery with its sunshine.
    Lucy Larcom (1824–1893)

    I hate to say it, Cory, but as a pool player you make a fine speedboat mechanic.
    Blake Edwards (b. 1922)