Copyright (c) Hyperion Entertainment and contributors.

Exec Item Pools

From AmigaOS Documentation Wiki
Revision as of 20:26, 29 April 2013 by Steven Solie (talk | contribs) (Created page with "= Introduction = An item pool is a special memory pool that can only allocate and deallocate predefined slabs of memory. Every allocation from this pool is exactly the same s...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

An item pool is a special memory pool that can only allocate and deallocate predefined slabs of memory. Every allocation from this pool is exactly the same size. There are no exceptions to this rule. Allocation and deallocating of these items is typically extremely fast (unless the pool needs to be enlarged or garbage collection takes place). Item pools are commonly called 'slab allocators', although the latter usually also refers to a kind of allocation that leaves data intact between calls.

Many applications frequently allocate very similar pieces of memory, like list nodes, rectangles, or similar structures. If these items are sufficiently large, their constant allocation and deallocation will produce a potentially large amount of fragmented memory nodes.

An item pool should be used whenever an application wants to allocate a large number of equally sized object. For example, an application allocating a couple thousand of Rectangle structures, or list items, could use an item pool for that to dramatically reduce the allocation time AND memory fragmentation.

The item pool is created with an initial number of item storage space, and automatically extends when space runs out, unless the maximum number of allocations is reached (settable using ASOITEM_MaxSize).

If set to non-NULL values, the constructor and destructor hooks are called with the newly allocated item or an item to be deallocated.

If the MEMF_CLEAR bit was set in the memory flags, the memory is cleared *before* the actual hook is invoked.

Similar to old exec memory pools, all memory allocated in the item pool is delete as soon as the item pool itself is freed (via a call to FreeSysObject).

Item Pool Organization

Creating an Item Pool