Malloc
Allocate Memory Block
Malloc() Opcode = 72 ($48)
U se d to alloca te so m e o f th e sy ste m 's free m e m o ry , a n d res erv e it for u se
b y th e p ro g ra m . A fte r th e p ro g ra m is finish ed u sin g th e m e m o ry , it sh ou ld
re tu rn it w ith M f re e (). M a llo c () c a n also b e u sed to d eterm in e th e size of
th e larg e st blo ck o f m e m o ry in th e free m em o ry p o ol. B eca u se of a b u g in
M a ll o c(), p ro g ra m s sh o u ld tr y to g e t all th e m em o ry th ey n ee d w ith o n e
b ig M a llo c () call, in stea d of se ve ral little o n es.
C macro format
lo n g a d d re ss, b y tes;
ad d re ss = M alloc(b yte s);
Machine language format
m o v e. 1 # b y te s , - (sp )
m o v e, w # $ 4 8 , - (sp )
tra p # 1
a d d q .l # 6 ,s p
Inputs
b y te s lo n g T he n u m b e r of b y tes o f m e m o ry to allo
ca te . If se t to - 1 , th e fu nctio n re tu rn s
th e size of th e la rg est blo ck of free m em
o ry in address.
Results
DO a d d re ss lo n g If th e fu n ctio n is able to allo cate bytes am o u n t of
m e m o ry , th e sta rtin g ad d re ss o f th e m e m o ry block
is retu rn ed h ere. If th e re isn 't sufficient free m e m
o ry to allo cate th e b lock th at w as req u ested , a v alu e
o f 0 is retu rn ed .
See also
M f re e ()
281