1. Choosing a pool class
This section contains a simple procedure for choosing a pool
class based on the properties of the data you plan to store in
it. The MPS works well if you can segregate your data into a variety
of pools, choosing the most appropriate pool class for each.
Note
Pool classes can differ in many ways not considered here: speed,
vulnerability to fragmentation, control overhead, and so on. This
procedure gives you a decent recommendation, but an expert in the
MPS might be able to make a better recommendation. And if no pool
class in the open source MPS exactly matches your needs, then it
is possible to develop new pool classes. See Writing a new pool class.
First, answer these questions about your data:
- Do you need the MPS to automatically reclaim unreachable blocks?
- Is it acceptable for the MPS to move blocks in memory and to place barriers(1) on
blocks? (For example, it might not be acceptable to move a block if
it has been passed to foreign code that remembered its
location.)
- Do your blocks contain references to blocks stored in
automatically managed pools (including references to other blocks
in the same pool, if it’s automatically managed)? And if so, are
these references exact, ambiguous or weak?
Second, look up your answers in this table to find the recommended
pool class to use:
2. Pool class properties
This table summarizes the properties of each pool class
provided by the open source MPS. For “block” properties, “yes” means
that the property holds for all blocks allocated from the pool. An
entry “—” indicates that a property makes no sense for a pool class:
for example, if blocks in a pool may not contain references,
it makes no sense to ask whether they may contain weak
references(1).
Property |
AMC |
AMCZ |
AMS |
AWL |
LO |
MFS |
MV |
MVFF |
MVT |
SNC |
Supports mps_alloc()? |
no |
no |
no |
no |
no |
yes |
yes |
yes |
no |
no |
Supports mps_free()? |
no |
no |
no |
no |
no |
yes |
yes |
yes |
yes |
no |
Supports allocation points? |
yes |
yes |
yes |
yes |
yes |
no |
no |
yes |
yes |
yes |
Supports allocation frames? |
yes |
yes |
yes |
yes |
yes |
no |
no |
yes |
yes |
yes |
Supports segregated allocation caches? |
no |
no |
no |
no |
no |
yes |
yes |
yes |
no |
no |
Timing of collections? |
auto |
auto |
auto |
auto |
auto |
— |
— |
— |
— |
— |
May contain references? |
yes |
no |
yes |
yes |
no |
no |
no |
no |
no |
yes |
May contain exact references? |
yes |
— |
yes |
yes |
— |
— |
— |
— |
— |
yes |
May contain ambiguous references? |
no |
— |
no |
no |
— |
— |
— |
— |
— |
no |
May contain weak references? |
no |
— |
no |
yes |
— |
— |
— |
— |
— |
no |
Allocations fixed or variable in size? |
var |
var |
var |
var |
var |
fixed |
var |
var |
var |
var |
Alignment? |
conf |
conf |
conf |
conf |
conf |
|
|
|
|
conf |
Dependent objects? |
no |
— |
no |
yes |
— |
— |
— |
— |
— |
no |
May use remote references? |
no |
— |
no |
no |
— |
— |
— |
— |
— |
no |
Blocks are automatically managed? |
yes |
yes |
yes |
yes |
yes |
no |
no |
no |
no |
no |
Blocks are manually managed? |
no |
no |
no |
no |
no |
yes |
yes |
yes |
yes |
yes |
Blocks are scanned? |
yes |
no |
yes |
yes |
no |
no |
no |
no |
no |
yes |
Blocks support base pointers only? |
yes |
yes |
yes |
yes |
yes |
— |
— |
— |
— |
yes |
Blocks support internal pointers? |
no |
no |
no |
no |
no |
— |
— |
— |
— |
no |
Blocks may be protected by barriers? |
yes |
no |
yes |
yes |
yes |
no |
no |
no |
no |
yes |
Blocks may move? |
yes |
yes |
no |
no |
no |
no |
no |
no |
no |
no |
Blocks may be finalized? |
yes |
yes |
yes |
yes |
yes |
no |
no |
no |
no |
no |
Blocks must be formatted? |
yes |
yes |
yes |
yes |
yes |
no |
no |
no |
no |
yes |
Blocks may belong to format auto-header? |
yes |
yes |
yes |
yes |
yes |
— |
— |
— |
— |
no |
3. Writing a new pool class
If none of the pool classes supplied with the MPS are quite right for
your application, don’t despair: the MPS is designed to be extensible
with new pool classes, and designed so that the properties of pools
are as orthogonal as possible. So if you need a pool containing
objects that are scannable but unformatted, or movable objects which
are manually managed, or a pool all of whose objects are roots, there
is no technical reason why it should not be possible to write it.
If you’d be interested in our developing new pool classes for your
requirements, or if you’ve started writing a new pool class
yourself, we’d love to hear from you.