Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Exec Item Pools"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
(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...")
 
Line 1: Line 1:
 
= Introduction =
 
= 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.
+
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.
 
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 =
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.
 
  +
  +
= 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).
 
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).
Line 13: Line 17:
 
If the MEMF_CLEAR bit was set in the memory flags, the memory is cleared *before* the actual hook is invoked.
 
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).
 
   
  +
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 =
 

Revision as of 20:30, 29 April 2013

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