Allocate
Memory
malloc
Syntax
#include
<stdlib.h>
void
*malloc(size)
size-t
size;
/*
size
of
block
in
bytes
*/
Defined
in
memory.
c in
rts.
src
Description
The malloc function allocates space for
an
object
of
size
bytes and returns
a pointer
to
the space.
If
malloc cannot allocate the packet (that
is,
if
it
runs
out
of
memory),
it
returns a null pointer
(0).
This function does
not
modify
the memory
it
allocates.
The memory that malloc
uses
is
in
a special memory pool or heap. A C
module called
memory.
c
reserves
memory for the heap
in
the .bss section.
The constant MEMORY-SIZE defines the size
of
the heap
as
1000 bytes.
If
necessary, you can change the size
of
the heap by change the value
of
MEMORY-SIZE and reassembling
memory.
c.
For more information,
see
Section 5.1.3, Dynamic Memory Allocation, on page
5-4.
6-49