I am using a library that uses malloc to dynamically create variables on the heap. I would also like to dynamically create an array in my main program by using malloc. Will the two conflict with each other? What issues will I run into?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I am using a library that uses malloc to dynamically create variables on the heap. I would also like to dynamically create an array in my main program by using malloc. Will the two conflict with each other? What issues will I run into?
MikeH said:Will the two conflict with each other?
No.
MikeH said:What issues will I run into?
Nothing beyond the usual issues seen with malloc memory. For instance, both the library and your code have to insure you don't write past either end of your malloc'd memory block.
Thanks and regards,
-George
There is nothing from TI. I understand there are some third party solutions. A search on dynamic program analysis shows some interesting links.
Thanks and regards,
-George
Depending on what you wish to accomplish, yes you can.
The value of the pointer is the beginning address of the object being pointed to. You can compare pointers to understand where they are allocated relative to each other.
In addition you can declare symbols in your linker command (.cmd) file to understand where your heap is. The section of memory used for malloc dynamic allocation is called .sysmem.
Say your .cmd looks like:
MEMORY
{
...
L2RAM: o = 0x00800000 l = 0x00020000 /* 128kB L2 RAM/Cache */
...
}
SECTIONS
{
...
.sysmem > L2RAM, RUN_START(_SYSMEM_START), RUN_END(_SYSMEM_END), RUN_SIZE(_SYSMEM_SIZE)
...
}
You can examine values in your program with things like:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
extern char const SYSMEM_START[];
extern char const SYSMEM_END[];
extern char const SYSMEM_SIZE[];
int main(void)
{
char const * start = SYSMEM_START;
char const * end = SYSMEM_END;
unsigned int len = (unsigned int) SYSMEM_SIZE;
char * p1 = malloc(256);
char * p2 = malloc(256);
assert(start<=p1 && p1<end);
assert(start<=p2 && p2<end);
if(p1 < p2)
{
printf("p1 is first\n");
}
return 0;
}