cancel
Showing results for 
Search instead for 
Did you mean: 

Memory overflow by using C++ operator ''new''

contact239955_stm1_st
Associate II
Posted on April 14, 2013 at 22:06

Hi everyone

I use STMF1 and STMF4 devices for some time now but I just started with STM32F0 devices (Discovery board) and I have a quite strange problem.

I created a class called Pin that can initialize any GPIO pin and use it (read, on, off, toggle, etc). When I create an instance of it like this :

Pin LED(GPIOC, GPIO_Pin_8);

everything is okay, but if I do this :

Pin* LED;

...

LED =

new

Pin(GPIOC, GPIO_Pin_8);

I have a flash memory overflow of 30492 bytes.

When I'm invoking the size command before and after creating an instance of Pin with the first method I have this :

Invoking: ARM Sourcery Mac OS X GNU Print Size

arm-none-eabi-size --format=berkeley base.elf

text data bss dec hex filename

4356 2132 1128 7616 1dc0 base.elf

Invoking: ARM Sourcery Mac OS X GNU Print Size

arm-none-eabi-size --format=berkeley base.elf

text data bss dec hex filename

4380 2132 1128 7640 1dd8 base.elf

Nothing extraordinary and I have still plenty of free space.

I'm using Eclipse with the GCC ARM toolchain on Mac OS X.

Does anyone have an idea about the origin of this problem?

This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
contact239955_stm1_st
Associate II
Posted on June 14, 2013 at 22:13

I found a solution for this problem.

the ''--specs=nano.specs'' argument has to be passed to the linker to enable newlib-nano. The memory overhead for the new operator is less than 800 Bytes.

Tested with GNU ARM 4.7

Hope it can helps someone