cancel
Showing results for 
Search instead for 
Did you mean: 

WICED Studio Wi-Fi Combo

New Contributor II

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 !!!

0 Likes
Reply
1 Solution
Employee

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.

View solution in original post

0 Likes
Reply
5 Replies
Anonymous
Not applicable

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.

0 Likes
Reply
New Contributor II

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

##### task name =cloud_thread,stack_size=2048,pri=2
##size=80,pv=0x2000e8c8
##size=2048,pv=0

Thank you

New Contributor II


0x2000e8c8 +2048 -0x20000000=61460 >61440 =>get pv=0;

the if highlight (61460) <=61424 malloc will success.


0 Likes
Reply
New Contributor II

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

##### task name =cloud_thread,stack_size=2048,pri=2
##size=80,pv=0x2000e8c8
##size=2048,pv=0

Thank you

0 Likes
Reply
Employee

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.

View solution in original post

0 Likes
Reply