WikiPendium

(beta)

Mfree()

WikiPendium :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ec2-13-58-39-23.us-east-2.compute.amazonaws.com

Mfree()


WORD Mfree( startadr )

VOIDP startadr;

Mfree() releases a block of memory previously reserved with Malloc() or Mxalloc() back into the GEMDOS free list.

Opcode

73 (0x49)

Availability

All GEMDOS versions.

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.

(StabyloRmv: MiNT algorithm has not been investigated yet)

Comments

Memory allocated by a process is automatically freed when the process calls Pterm().

See Also

Malloc(), Mxalloc(), MemoryManagement

Il n'y a pas de commentaire sur cette page. [Afficher commentaires/formulaire]