rand/srand
7-44
Random Integer
rand/srand
Syntax
#include <stdlib.h>
int
rand
(void);
void
srand
(unsigned int seed);
Defined in
rand.c in rts.src
Description
Two functions work together to provide pseudorandom sequence generation:
-
The rand function returns pseudorandom integers in the range
0—RAND_MAX. For the TMS320C2x/C2xx/C5x C compiler, the value of
RAND_MAX is 2147483646 (2
31
−
2).
-
The srand function sets the value of the seed so that a subsequent call to
the rand function produces a new sequence of pseudorandom numbers.
The srand function does not return a value.
If you call rand before calling srand, rand generates the same sequence it
would produce if you first called srand with a seed value of 1. If you call srand
with the same seed value, rand generates the same sequence of numbers.
Change Heap Size
realloc
Syntax
#include <stdlib.h>
void *
realloc
(void *packet, size_t size);
Defined in
memory.c in rts.src
Description
The realloc function changes the size of the allocated memory pointed to by
packet 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.
-
If packet is 0, realloc behaves like malloc.
-
If packet points to unallocated space, function takes no action and returns.
-
If the space cannot be allocated, the original memory space is not
changed, and realloc returns 0.
-
If size is 0 and packet is not null, realloc frees the space packet points to.
If the entire object must be moved to allocate more space, 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. The
constant __SYSTEM_SIZE defines the size of the heap as 1K words. You can
change this amount at link time by invoking the linker with the
−
heap option
specifying the desired size of the heap directly after the option. For more
information, see section 6.1.4,
Dynamic Memory Allocation
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...