CYW20719 wiced_memory_allocate

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
jakub
Level 1
Level 1
10 sign-ins 5 sign-ins First like given

Hello,

Can someone please explain how wiced_memory_allocate() allocates the memory? 

I tried wiced_bt_create_pool() to create some pools and then checked using wiced_bt_get_buffer_usage(), but the pools stats don't change no matter how much I allocate or free using wiced_memory_allocate().. Where does the memory come from and where can I check how much memory I have left? Can I modify the size of the "dynamic memory"? And/or how I am supposed to use the wiced_memory_allocate()?

Thanks,

Jakub.

0 Likes
1 Solution
DheerajPK_41
Moderator
Moderator
Moderator
750 replies posted 500 likes received 500 replies posted

Update:

Please use the below code in your program to check the free memory available and the buffer stats. Whenever you initialize or use the available RAM (by initializing new variables, calling functions,..) it is expected to reduce the free memory available for the application implementation.

  • To monitor available free memory use

#include "wiced_memory.h"

wiced_memory_get_free_bytes()

  • To monitor the buffer usage call the below function where ever you need or periodically on a timer.

#include "wiced_memory.h"

void print_buf_use()

{

    wiced_bt_buffer_statistics_t buff_stat[4];

    wiced_bt_get_buffer_usage(buff_stat, sizeof(buff_stat));

    WICED_BT_TRACE("pool size/cur/max/total %d/%d/%d/%d %d/%d/%d/%d %d/%d/%d/%d %d/%d/%d/%d\n",

        buff_stat[0].pool_size, buff_stat[0].current_allocated_count, buff_stat[0].max_allocated_count, buff_stat[0].total_count,

        buff_stat[1].pool_size, buff_stat[1].current_allocated_count, buff_stat[1].max_allocated_count, buff_stat[1].total_count,

        buff_stat[2].pool_size, buff_stat[2].current_allocated_count, buff_stat[2].max_allocated_count, buff_stat[2].total_count,

        buff_stat[3].pool_size, buff_stat[3].current_allocated_count, buff_stat[3].max_allocated_count, buff_stat[3].total_count);

}

Thanks,

-Dheeraj.P.K

View solution in original post

0 Likes
4 Replies
DheerajPK_41
Moderator
Moderator
Moderator
750 replies posted 500 likes received 500 replies posted

Hi,

Please use wiced_memory_get_free_bytes to know the free RAM left for your application logic. This free RAM is the memory free after all Stack, Static and Dynamic usage which can be used for the application implementation.

Thanks,

-Dheeraj.P.K

0 Likes
jakub
Level 1
Level 1
10 sign-ins 5 sign-ins First like given

Hi Dheeraj,

Can you please elaborate on how to use that free RAM and how track it as well because wiced_memory_get_free_bytes gives the same value before and after allocation (wiced_memory_allocate)..

Thanks,

Jakub.

0 Likes
jakub
Level 1
Level 1
10 sign-ins 5 sign-ins First like given

Hello,

I would really appreciate any help as I am pretty stuck with this and the documentation does not help at all.

The wiced_memory.h has the following:

/**
* Function wiced_memory_allocate
*
* Allocates memory from Dynamic Memory pools
*
* @param[in] size :size of the memory to be allocated
*
* @return pointer to the allocated memory on success
* NULL on failure
*/
void* wiced_memory_allocate( uint32_t size );

However this is the only place where "dynamic memory pools" are ever mentioned.

This document https://infineon.github.io/btsdk-docs/BT-SDK/AIROC-Application-Buffer-Pools.pdf is not helpful either.

I can see that the wiced_memory_get_free_bytes gives smaller free bytes if I use wiced_bt_create_pool. However wiced_memory_allocate does not change the usage of the buffers at all when I check them using wiced_bt_get_buffer_usage. I assume that the "heap" or "dynamic memory pools" are somehow somewhere initialized at startup and wiced_memory_allocate uses them. Is there a way to specify the size of these "dynamic memory pools"? And any way to track their usage?

Thanks for any help,

Jakub.

0 Likes
DheerajPK_41
Moderator
Moderator
Moderator
750 replies posted 500 likes received 500 replies posted

Update:

Please use the below code in your program to check the free memory available and the buffer stats. Whenever you initialize or use the available RAM (by initializing new variables, calling functions,..) it is expected to reduce the free memory available for the application implementation.

  • To monitor available free memory use

#include "wiced_memory.h"

wiced_memory_get_free_bytes()

  • To monitor the buffer usage call the below function where ever you need or periodically on a timer.

#include "wiced_memory.h"

void print_buf_use()

{

    wiced_bt_buffer_statistics_t buff_stat[4];

    wiced_bt_get_buffer_usage(buff_stat, sizeof(buff_stat));

    WICED_BT_TRACE("pool size/cur/max/total %d/%d/%d/%d %d/%d/%d/%d %d/%d/%d/%d %d/%d/%d/%d\n",

        buff_stat[0].pool_size, buff_stat[0].current_allocated_count, buff_stat[0].max_allocated_count, buff_stat[0].total_count,

        buff_stat[1].pool_size, buff_stat[1].current_allocated_count, buff_stat[1].max_allocated_count, buff_stat[1].total_count,

        buff_stat[2].pool_size, buff_stat[2].current_allocated_count, buff_stat[2].max_allocated_count, buff_stat[2].total_count,

        buff_stat[3].pool_size, buff_stat[3].current_allocated_count, buff_stat[3].max_allocated_count, buff_stat[3].total_count);

}

Thanks,

-Dheeraj.P.K

0 Likes