Running out of heap memory (realloc and calloc)

4 posts / 0 new
Last post
brian
Offline
Last seen:5年11个月前
Expert Master
加入ed:2014-10-16 18:10
Running out of heap memory (realloc and calloc)

I am running out of memory saving the minimal number of services, characteristics, and descriptors during service discovery to enable notifications/indications. Realloc and calloc fails. I am looking to get/configure more memory. I look at this in *_config.h

#if defined(CFG_EXT_SLEEP) || !defined(CFG_DEEP_SLEEP)
#define REINIT_DESCRIPT_BUF 0 //0: keep in RetRAM, 1: re-init is required (set to 0 when Extended Sleep is used)
#define USE_MEMORY_MAP EXT_SLEEP_SETUP

#else
/*The following are valid for BLE_CONNECTION_MAX_USER == 1. Please use the results of the excel tool! */
#define REINIT_DESCRIPT_BUF 0 //0: keep in RetRAM, 1: re-init is required (set to 0 when Extended Sleep is used)
#define USE_MEMORY_MAP DEEP_SLEEP_SETUP
#定义DB_HEAP_SZ 1024
#define ENV_HEAP_SZ 328
#define MSG_HEAP_SZ 1312
#define NON_RET_HEAP_SZ 1024
#endif

And also look at the excel spreadsheet which I just downloaded (not to say I understand how to use it). I have a central supporting the maximum number of connections (6) but exposing no services. In all cases in the spreadsheet I see DB_HEAP_SZ set to 1024. Why? To me that wastes 1024 bytes of memory which would go a long way in my case.

What I don't understand is what memory is being used when I realloc or calloc. Trying to read the names and make some sense out of it I assume it is either ENV_HEAP_SZ or NON_RET_HEAP_SZ. In any case,

1. how do I find out how much memory I can reserve for these various fields?
2. May I set the DB_HEAP_SZ to zero?
3. Is there anything else (code, methods, files, etc.) that has to do with the data base that I can remove?
4. How do I reconcile these spreadsheet settings with items like #define RWIP_HEAP_NON_RET_SIZE_USER 2048 //(1024 * BLE_CONNECTION_MAX_USER) in em_map_ble_user.h file?

Also, changing the above to:
#if defined(CFG_EXT_SLEEP) || !defined(CFG_DEEP_SLEEP)
#define REINIT_DESCRIPT_BUF 0 //0: keep in RetRAM, 1: re-init is required (set to 0 when Extended Sleep is used)
#define USE_MEMORY_MAP EXT_SLEEP_SETUP

#else
/*The following are valid for BLE_CONNECTION_MAX_USER == 1. Please use the results of the excel tool! */
#define REINIT_DESCRIPT_BUF 0 //0: keep in RetRAM, 1: re-init is required (set to 0 when Extended Sleep is used)
#define USE_MEMORY_MAP DEEP_SLEEP_SETUP
#define DB_HEAP_SZ 0 //1024
#define ENV_HEAP_SZ 1980 //328
#define MSG_HEAP_SZ 4844 //1312
#define NON_RET_HEAP_SZ 2060 //1024
#endif

made no difference; calloc failed at exactly the same place.

TR_Dialog
Offline
Last seen:2 weeks 3 days ago
Staff
加入ed:2014-06-30 23:52
When you detect you are

When you detect you are running out of memory it can be due to one of two reasons: 1) a memory leakage 2) insufficient heap size. If you have already ruled out memory leakage, then it is time to focus on the heap size, as you have described above. One way to debug this issue will be to examine the map file. That will give you an idea about how much head room you have, and adjust your software accordingly.

brian
Offline
Last seen:5年11个月前
Expert Master
加入ed:2014-10-16 18:10
TR_Dialog,

TR_Dialog,

Unfortunately what you have stated I already know. What I am asking is what the meaning of the various heap message allocations do. Where is user memory allocated, can I even control it, etc.? How does one use the information in the spreadsheet? There is no documentation anywhere regarding any of this material. Without any understanding as to what the various heap allocations mean, I have blindly tried altering some of the above based upon the word (guessing to what they might mean). As you see from my remark, none of the changes I made had any affect on the calloc failure. Happened at exactly the same place. I don't know the other consequences of these changes but so far it appears to have no affect.

Please point me to some documentation that explains what the various heap allocations mean, how (and even if) I can change them, and what do I need to do to control the heap size for the user (that I would grab by using realloc and/or calloc).

TR_Dialog
Offline
Last seen:2 weeks 3 days ago
Staff
加入ed:2014-06-30 23:52
The available documentation

The available documentation for memory usage, and the "Memory Map Excel Tool" is as follows: "UM-B-011 : User Manual - DA14580 Memory map and scatter file 1.1 "

http://support.dialog-semiconductor.com/system/files/restricted/UM-B-011.pdf