Using a "placement new" to locate an object outside the heap

07 Feb 2012

Hi All,

I've been working on a project that manages 128 I/O pins through the use of some I2C expanders. The problem is, once I load up the code, I'm left with 8K of heap - not enough to even load the LWIP stack and run it.

Because the hardware configuration is static between boots, I was thinking of using the "other 32K" of RAM on the board.

Is this the right approach or are there any hints on how to scrounge back some RAM?

Thanks,

Anthony

Replies

07 Feb 2012

Do you use mbed libs? After I replaced mbed libs by own code I could reduce memory consumption from 21kB down to1.6kB

07 Feb 2012

Hi Rene,

I am using the Mbed libs as I am using the online compiler. I don't really want to go to offline - the online approach (zero tools) was part of the appeal of the Mbed...

Mbed folks: Is there any optimisation possible on the compiler? Whilst it is plug&go at the moment, there aren't any nerd-nobs to tweak either the build process or the code that's output

Anthony

14 Feb 2012

I have used the following code in the past to call from the beginning of my program to dump how much memory has been used up in each of the RAM banks by the compiler for statics and globals.

Code

// These external symbols are maintained by the linker to indicate the
// location of various regions in the device's memory.  They will be used by
// DisplayRAMBanks() to dump the size of each RAM bank to stdout.
extern unsigned int Image$$RW_IRAM1$$Base;
extern unsigned int Image$$RW_IRAM1$$ZI$$Limit;
extern unsigned int Image$$RW_IRAM2$$Base;
extern unsigned int Image$$RW_IRAM2$$ZI$$Limit;
extern unsigned int Image$$RW_IRAM3$$Base;
extern unsigned int Image$$RW_IRAM3$$ZI$$Limit;


// Displays the size of static allocations for each RAM bank as indicated by
// ARM linker to stdout.
static void DisplayRAMBanks(void)
{
    printf("Static RAM bank allocations\r\n");
    printf("  Main RAM = %u\r\n", (unsigned int)&Image$$RW_IRAM1$$ZI$$Limit - 
                                  (unsigned int)&Image$$RW_IRAM1$$Base);
    printf("  RAM0     = %u\r\n", (unsigned int)&Image$$RW_IRAM2$$ZI$$Limit -
                                  (unsigned int)&Image$$RW_IRAM2$$Base);
    printf("  RAM1     = %u\r\n", (unsigned int)&Image$$RW_IRAM3$$ZI$$Limit -
                                  (unsigned int)&Image$$RW_IRAM3$$Base);
}

To move a global from main RAM to the RAM0 bank, you can declare it something like:

Code

__attribute((section("AHBSRAM0"),aligned)) char LargeBuffer[1024];

Please log in to post a reply.