Charm Pool Library (pool) 

The pool library contains procedures allowing applications to efficiently manage small blocks of heap memory locally. It is automatically used for Charm new record and module requests if linked into a program. Free lists of different block sizes are kept for rapid allocation, and if extra memory is required, it is allocated from the application heap in 1Kb blocks:

Get block

export proc get (int bytes) int

  • passed bytes - block size
  • returns address of block
  1. Do not allocate blocks of memory of greater size than 1Kb; instead allocate using the runtime library heap procedures directly.
  2. A block get may fail if the heap becomes exhausted. Re-run the application setting a larger Application Next allocation.
  3. The returned block is untyped. Typically it will be cast to a reference to a type e.g.
            ref array real zi := [Pool.get (size (real) * 5)];
    to allocate an array of 5 floating pointer numbers. Note the use of the size keyword to help in finding the required block size.

Free block

export proc free (int block)

  • passed block - address of block
  1. Be careful to pass the address of an allocated block; otherwise behaviour is undefined.

Resize block

export proc resize (int block, int size)

    • passed block - address of block
    •             size new block size
    1. Do not use this procedure to attempt to resize a block to a larger size than the original block. Instead allocate a new block, copy the contents of the old block to it and release the old block.

    Make a Free Website with Yola.