Page 1 of 1

How to use the memory of MALLOC_CAP_INTERNAL ?

Posted: Thu Oct 25, 2018 4:54 am
by ZHDX227
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.

Re: How to use the memory of MALLOC_CAP_INTERNAL ?

Posted: Thu Oct 25, 2018 6:48 am
by WiFive
Not all memory is MALLOC_CAP_DMA and MALLOC_CAP_8BIT, so it isn't "reserved" but it can't do those things.

Re: How to use the memory of MALLOC_CAP_INTERNAL ?

Posted: Thu Oct 25, 2018 7:52 am
by ZHDX227
Thanks.

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

Regards,
Terry

Re: How to use the memory of MALLOC_CAP_INTERNAL ?

Posted: Thu Nov 15, 2018 3:29 pm
by ZHDX227
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