The heap does not have fixed size, but shares RAM with the stack and they grow towards each other. See here for the pictures: http://mbed.org/handbook/Memory-Model
I would suggest you to try to reduce heap usage. Use static/global objects, use constant strings if possible, use automatic (stack) variables which are destroyed on exit from the function, and so on. For example, instead of using dynamic allocation for your cmd structs, you can make them static:
struct cmd {
const char *cmdstr;
int subs;
int cid;
const char *parms;
const char *cmddescr;
const char *parmdescr;
};
static const cmd MACRO = { "Macro", GLOBALCMD, CID_MACRO, "%s", "Define macro (sp->_, cr->|)", "command(s)" };
This will create the same structure as before, but all string pointers will be static and pointing into ROM memory, saving RAM for other purposes.
I would also probably use a simple array for the commands instead of vector. If you feel you need to change the command list at runtime, you could use a vector to keep them inside Cmdb, but you don't really need a vector when initializing it.
So, for example:
static const cmd c1 = { "Test", SUBSYSTEM, CID_TEST, "" , "* Test Subsystem", ""};
static const cmd c2 = { "Int" , CID_TEST , CID_INT , "%i", "* Int as parameter" ,"dummy"};
struct cmd my_cmds[] = { c1, c2, COMMANDS, BOOT, ECHO, ..., IDLE, HELP };
#define MY_CMD_COUNT sizeof(my_cmds)/sizeof(my_cmds[0]) // a trick to count number of items in an array
Cmdb cmdb(serial, my_cmds, MY_CMD_COUNT, &my_dispatcher);
Again, this will store the initial list of commands in ROM instead of wasting RAM for transient lists.
Hi,
I'm currently working on a program using my CMDB lib which uses an array of object (each of wich will malloc some strings).
At a certain point the prompt does not appear anymore. When i disable one of more commands (so the table is a bit smaller, things start to work again).
As i suspect the heap size, is there a way to increase it?
wvd_vegt