Ceci est une version archivée de
Mfree() à 2006-02-23 16:17:48.
WORD Mfree( startadr )
VOIDP startadr;
Opcode
73 (0x49)
Availability
Parameters
startadr is the starting address of the block to be freed. This address must be the same as that returned by the corresponding
Malloc() or
Mxalloc() call.
Binding
pea startadr
move.w #$49,-(sp)
trap #1
addq.l #6,sp
Return Value
Mfree() returns
E_OK (
0) if the block was freed successfully or a negative
GEMDOS error code otherwise.
Caveats
As implemented by
TOS,
Mfree() is slower when you're using
FOLDRxxx.PRG with large
xxx. The larger
xxx, the slower
Mfree(). With
xxx greater than
300, it becomes significantly slower, and even more with
999. This is due to the linear search algorithm used by
TOS to find the block to be freed in the allocated blocks list. As
FOLDRxxx.PRG increases the size of this list to be able to allocate more blocks, it has a direct impact on
Mfree() speed.
MagiC? uses a different way of holding the information of allocated blocks, which leads to a (virtually) unlimited amount of allocated block and an
Mfree() algorithm that works in constant time. The drawbacks of the
MagiC? method is that when a program makes a buffer overflow (i.e. it writes data past the end of an allocated block), then
Mfree() may badly crash which lead to a critical and unrecoverable error for the whole system. So, the
MagiC? algorithm is faster but less robust and very sensitive to buffer overflows.
Comments
Memory allocated by a process is automatically freed when the process calls
Pterm().
See Also