Copyright (c) Hyperion Entertainment and contributors.

Exec Item Pools

From AmigaOS Documentation Wiki
Revision as of 19:30, 29 April 2013 by Steven Solie (talk | contribs)
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 deallocation 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.

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

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.

Item Pool Organization

Creating an Item Pool

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.

Deleting an Item Pool

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).