- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear,
I use MCU STM32F103RD(64KB SRAM),when I have used 60KB I call malloc(10) will fail ,can't get space ?
Thanks a lot !!!
Solved! Go to Solution.
- Labels:
-
Memory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Since MALLOC will allocate 4K blocks and runs in virtual memory, sometimes you can have fragments. (Usually not an issue in systems with huge memory.)
Things like "scan results" and other functions rely on MALLOC, so it is best not to use every last bit or rely on it too heavily.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume by
I have used 60KB
you mean that when it compiles, that is how much Static RAM the compiler has told you it is using. That means that you have ~4KB of RAM to dynamically allocate using malloc(). I've found at least some functions in the SDK that use dynamic memory allocation, so it is likely that they are taking up those 4 KB (and probably trying to use more), which is why your malloc() call is failing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you replying. complies use Staic Ram 36KB, SDK some functions use about 24KB ,then I call create thread that call malloc then will fail.
I add DbgPrintf which put debug info to temp buf at pvPortMalloc function.
extern void DbgPrintf(const char *fmt,...);
void *pvPortMalloc( size_t xWantedSize )
{
void *pvReturn;
int a=(int)xWantedSize;
vTaskSuspendAll();
{
pvReturn = malloc( xWantedSize );
DbgPrintf("##size=%d,pv=0x%x\r\n",a,(unsigned int)pvReturn);
}
xTaskResumeAll();
...
return pvReturn;
}
Then I get debug message
##size=80,pv=0x2000e8c8
##size=2048,pv=0
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
0x2000e8c8 +2048 -0x20000000=61460 >61440 =>get pv=0;
the if highlight (61460) <=61424 malloc will success.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you replying. complies use Staic Ram 36KB, SDK some functions use about 24KB ,then I call create thread that call malloc then will fail.
I add DbgPrintf which put debug info to temp buf at pvPortMalloc function.
extern void DbgPrintf(const char *fmt,...);
void *pvPortMalloc( size_t xWantedSize )
{
void *pvReturn;
int a=(int)xWantedSize;
vTaskSuspendAll();
{
pvReturn = malloc( xWantedSize );
DbgPrintf("##size=%d,pv=0x%x\r\n",a,(unsigned int)pvReturn);
}
xTaskResumeAll();
...
return pvReturn;
}
Then I get debug message
##size=80,pv=0x2000e8c8
##size=2048,pv=0
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Since MALLOC will allocate 4K blocks and runs in virtual memory, sometimes you can have fragments. (Usually not an issue in systems with huge memory.)
Things like "scan results" and other functions rely on MALLOC, so it is best not to use every last bit or rely on it too heavily.
Hope this helps.