(with the friendly permission of the original author, Andreas Kleinert)
New in release 2.01:
- Added a workarount for stupid "SaferPatches" clones.
New in release 2.00:
- Rewritten in assembly language, much shorter file
- Tries a partial flush first, instead of removing
all libraries on failure.
- Removed unnecessary AllocVec patch since it calls
- Added workarounds for bugs in the layers.lib
AllocP32 will be part of a major memory defragmentizer project still to be
published, called PoolMem. Please stay tuned!
WARNING: THIS PATCH ISN'T WITHOUT QUIRKS! READ THIS FILE CAREFULLY BEFORE
INSTALLING ALLOCP32. REALLY, I MEAN IT!
AllocP32 is identical to AllocP EXCEPT that it allocates memory in 32 byte
wide blocks to avoid conflicts between PPC and MC68K microprocessors. If
you don't have a PPC board, this patch is most likely unnecessary and will
only slow down your computer and waste memory. Use AllocP instead.
This program is still in an "experimental" phase, even though it has been
tested now. No guarantee that this works with a PPC board, I don't have
one for testing! (However, it's welcome as a gift.... ;-)
Sometimes programs fail with a "not enough memory" error,
but after calling "avail flush" the same operation does
succeed without problems.
If AllocMem routine in the ROMs did not find enough memory,
it tries to flush disk based libraries and devices and,
afterwards, tries again to reallocate the memory.
However, due to a design flaw of the AllocMem() routine,
this memory flushing does not have the desired result some-
times - even though the libraries have been informed to
remove themselves, the memory is not available directly
afterwards. The AllocMem() call will fail anyways, EVEN THOUGH
the requiested memory will be available immediatly after completion
The reasons for this strange behaiviour are rather technical
and explained below, for the interested user.
This patch does ensure that AllocMem/AllocVec won't
fail unless there's really no memory available, even
by flushing. It does ALSO, and in addition to AllocP,
ensure that the allocated memory is contained in
32 byte memory blocks and not on boundaries of these
blocks, so match in one cache line of either the PPC
or the MC68K microprocessor, not in both.
This avoids that parts of the allocated memory is in
different caches of the two CPUs and not up-to-date.
The patch DOES NOT ensure that the memory is 32 byte
aligned! (The current implemenation returns always
memory eight bytes on top of a 32 byte boundary,
but don't take this for sure!)
The patch does NOT apply to structures allocated by the
layer library so take care! The reason is a design flaw
(avoiding to call this a serious bug) in the layers
library, which causes also some trouble for MungWall
and MemSniff. See below for what this bug is about.
WARNING: Due to this workaround of the layers.libary bug,
it is currently NOT allowed to install an AllocMem()
patch ON TOP of this one or it will CRASH! If a second
patch of AllocMem is unavoidable, run AllocP32 LAST!
To find out which patches are installed in your system,
get the "SaferPatches" package from my home page at
or from the AmiNet.
Because of the memory alignment, AllocP32 must allocate
more memory than requested and will "round up" the memory
size to fit entirely in 32 byte blocks. This DOES, of course,
waste memory! Don't use this patch without good reason!
(good reason = a PPC board!)
Note: Works now for all operating systems and all CPUs,
is no longer restricted to V37 or MC'20.
Does not require a PPC, but if you don't have one,
try AllocP instead - it's much less memory consuming.
Usage: Try starting in the Shell/CLI.
If it does run stable, copy it into
your C: directory and add it
somewhere into your s:user-startup
You use this patch at your own risk.
No guarantee for anything.
Source code in assembly language included, requires the DevPac assembler
and my macro package at dev/asm/DvPkMacros.lha in the AmiNet.
All mentioned trademarks are subject to their owners.
The design flaw in AllocMem():
When looking closely at the ROM routine of AllocMem(), you'll
notice that a memory flush is TRIED if the first allocation
Why does AllocMem then fail, even though if enough memory
Consider the following situation:
A library has launched a sub-task for control of some of its
features. This sub-task could be used for disk I-O, for example.
If this hypothetical library has to be expunged, it can't do
this on its own because this will release memory of the sub-task
which is still running. This sub-task must be informed somehow
that its memory must go. While this is in principle simple to do -
just send a message to the sub task - the library can't wait for
an answer of the sub-task because this would brake the Forbid()
state, which is illegal at this point of the operation.
The only solution for the library is to leave the memory flush
to the sub task and to return to the low-memory handler of exec
WITHOUT trying to remove itself - leaving this to its sub-task.
On the other hand, since multitasking is still forbidden, there
is NO chance that this subtask will actually get a chance to
remove the library, leaving it in memory and causing the
allocation failure. EVEN THOUGH the library was informed to
get removed, there is no chance of doing this while flushing.
However, as soon as exec leaves the AllocMem routine, multi-
tasking will be turned on again, thus causing a task switch to
the subtask and NOW causing the removal of the library - to late
to have any effect.
AllocP tries to avoid this situation by calling AllocMem a
The bug in the layers.library:
The layers.library allocates memory for tempory region information
in big chunks and cuts this memory apart in smaller pieces, freeing
the snippets individually. This is according to the RKRM standards
ILLEGAL and has caused a lot of problems (including crashes of
earlier versions of AllocP32) not only for AllocP32.
Please DO NOT share layers.library structures between different CPUs
until this has found a solution in a bugfixed OS version. If this
can't be avoided, flush the data caches!
The THOR-Software Licence
This License applies to the computer programs known as "AllocP32".
The "Program", below, refers to such program.
The programs and files in this distribution are freely distributable
under the restrictions stated below, but are also Copyright (c)
Distribution of the Program by a commercial organization without written
permission from the author to any third party is prohibited if any payment
is made in connection with such distribution, whether directly
(as in payment for a copy of the Program) or indirectly (as in payment
for some service related to the Program, or payment for some product
or service that includes a copy of the Program "without charge";
these are only examples, and not an exhaustive enumeration of prohibited
activities). However, the following methods of distribution involving
payment shall not in and of themselves be a violation of this restriction:
(i) Posting the Program on a public access information storage and
retrieval service for which a fee is received for retrieving information
(such as an on-line service), provided that the fee is not
content-dependent (i.e., the fee would be the same for retrieving the same
volume of information consisting of random data).
(ii) Distributing the Program on a CD-ROM, provided that the files
containing the Program are reproduced entirely and verbatim on such
CD-ROM, and provided further that all information on such CD-ROM be
redistributable for non-commercial purposes without charge.
Everything in this distribution must be kept together, in original
and unmodified form.
THE PROGRAM IS PROVIDED TO YOU "AS IS," WITHOUT WARRANTY. THERE IS NO
WARRANTY FOR THE PROGRAM, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE ENTIRE
RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD
THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
SERVICING, REPAIR OR CORRECTION.
IF YOU DO NOT ACCEPT THIS LICENCE, YOU MUST DELETE ALL FILES CONTAINED IN