realloc
Syntax
#include
<stdlib.h>
void
*realloc(ptr,
size)
Change
Heap
Size
void
*ptr;
/*
pointer
to
object
to
change
*/
size-t
size;
/*
new
size
(in
bytes)
of
packet
*/
Defined
in
memory.
c in
rts.
src
Description
The realloc
function
changes the size
of
the allocated memory pointed
to
by
ptr,
to
the size specified in bytes by
size.
The contents
of
the memory
space
(up
to
the lesser
of
the old and
new
sizes) is not changed.
6-62
•
If
ptr
is
0, then realloc behaves like malloc.
•
If
ptr
points
to
unallocated space, the function takes no action and
returns.
•
If
the space cannot be allocated, the original memory space
is
not
changed and realloc returns
O.
•
If
size=O
and
ptr
is
not
null, then realloc frees the space
that
ptr
points to.
If, in oreler
to
allocate more space, the entire object must
be
moved, realloc
returns a pointer
to
the
new
space.
Any
memory freed
by
this operation
is
deallocated.
If
an
error occurs, the
function
returns a
null
pointer
(0).
The memory
that
realloc 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.