Ceci est une version archivée de
Malloc() à 2006-02-22 15:28:38.
VOIDP Malloc( amount )
LONG amount;
Malloc() requests a block of memory for use by an application.
Opcode
72 (0x48)
Availability
Parameters
amount specifies the amount of memory (in bytes) you wish to allocate. You may pass a value of -1L in which case the function will return the size of the largest free block of memory.
Binding
move.l amount,-(sp)
move.w #$48,-(sp)
trap #1
addq.l #6,sp
Return Value
Malloc() returns
NULL if there is no block large enough to fill the request or a pointer to the allocated block if the request was satisfied. The memory allocated will be chosen based on the status of the processes' load flags. To specify the memory requirements in more detail, use
Mxalloc().
Caveats
Prior to
GEMDOS version 0.15,
Malloc( 0L ) will return a pointer to invalid memory as opposed to failing as it should.
Comments
Because
GEMDOS can only allocate a limited amount of blocks per process (as few as 20 depending on the version of
GEMDOS), applications should limit their usage of this call by allocating a few large blocks instead of many small blocks, or use a memory manager (like
malloc() provided in the C language) if possible.
See Also