How to use the memory of MALLOC_CAP_INTERNAL ?

ZHDX227
Posts: 16
Joined: Thu Oct 25, 2018 4:43 am

How to use the memory of MALLOC_CAP_INTERNAL ?

Postby ZHDX227 » Thu Oct 25, 2018 4:54 am

I recently get OOM issue,

heap_caps_get_free_size(MALLOC_CAP_DEFAULT) returns 112

heap_caps_get_free_size(MALLOC_CAP_INTERNAL) returns 70284

I want to use the MALLOC_CAP_INTERNAL ,

but ,

heap_caps_malloc(size, MALLOC_CAP_DEFAULT) return 0
malloc(size) return 0
heap_caps_malloc(size, MALLOC_CAP_8BIT) return 0
heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT) return 0
heap_caps_malloc(size, MALLOC_CAP_DMA) return 0
heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_DMA) return 0

----

heap_caps_malloc(size, MALLOC_CAP_INTERNAL) return OK

but the memory caused

Guru Meditation Error: Core 1 panic'ed (LoadStoreError). Exception was unhandled.

----

I don't know why it reserved 70K MALLOC_CAP_INTERNAL ,

Is there any config settings that can reduce the size of MALLOC_CAP_INTERNAL ?


Thanks.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How to use the memory of MALLOC_CAP_INTERNAL ?

Postby WiFive » Thu Oct 25, 2018 6:48 am

Not all memory is MALLOC_CAP_DMA and MALLOC_CAP_8BIT, so it isn't "reserved" but it can't do those things.

ZHDX227
Posts: 16
Joined: Thu Oct 25, 2018 4:43 am

Re: How to use the memory of MALLOC_CAP_INTERNAL ?

Postby ZHDX227 » Thu Oct 25, 2018 7:52 am

Thanks.

Now I know that's the IRAM and it's not able to work as the DRAM

Regards,
Terry

ZHDX227
Posts: 16
Joined: Thu Oct 25, 2018 4:43 am

Re: How to use the memory of MALLOC_CAP_INTERNAL ?

Postby ZHDX227 » Thu Nov 15, 2018 3:29 pm

Just share 2 ideas

1 - set all int32,int64,pointer to IRAM_ATTR

staic IRAM_ATTR int intval=0;
staic IRAM_ATTR void* ptrval=NULL;

2 - use custom allocator for std::vector<int> , etc

ptr=heap_caps_malloc(size, MALLOC_CAP_32BIT);
return ptr!=NULL?ptr:malloc(size);

Regards,
Terry

Who is online

Users browsing this forum: No registered users and 115 guests