Strange memory consumption

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Strange memory consumption

Jump to solution
1,254 Views
diegobarile
Contributor II

Hello everyone.


We starting to develop a C++ project plus FREERtos 9.x based on a MCU LPC11C24.

As soon we instatiate two empty C++ classes in the main, inside the map file we are seeing a strange memory consumption.
For example the linker reserve more than 0x400 bytes for a function named "__malloc_av_" and other 0x400 bytes for one object named "_impure_ptr".

 

We suspect that some linker options are wrong and the system puts into the RAM functions can could be stored into the Flash.

 

What is wrong?

 

I've attached our map file.

 

Thanks in advance.
Diego.

Original Attachment has been moved to: PressureLevelSensor.map.zip

Labels (2)
1 Solution
875 Views
converse
Senior Contributor V

While it is possible to use C++ with the LPC11xx family, in reality, you will be programming in a slightly better C as so many of the useful features of C++ are really hungry for memory - both code (flash) and heap/stack (RAM). The 11C24 has just 32k of flash and 8k of ram. Also, although FreeRTOS can be pretty small, depending on features you are using, you are going to really struggle to use both C++ and any RTOS with such a small amount of memory. I would certainly recommend using an RTOS, and FreeRTOs is as good as any, I would not recommend C++ with this device.

Having said that, you may want to read this article on Embedded.com:

Modern C++ in embedded systems – Part 1: Myth and Reality | Embedded 

View solution in original post

3 Replies
875 Views
rocketdawg2
Contributor II

Just for grins, instantiate the objects as globals.

It is part of newlib.

I am fairly certain that objects instantiated within the scope of a function are not really placed on the stack.  Malloc is called to create the object and then destroyed when the function goes out of scope.  main() is a function.  Hence, the compiler added the malloc functions.

__impure_ptr

it has to do with reentrancy.  You cannot remove it because it is used for more than that, but I believe you can shrink it by building newlib with the following option

  --enable-newlib-reent-small

also see

[RTOS Support] _impure_ptr not setup when entering first task 

875 Views
diegobarile
Contributor II

Thank you David for your reply.


I'll do additional tests ASAP.

But the mother of all questions is: is the LPC11C24 processor suitable to run a C++ project with FreeRTOS or is necessary to choose a compromise (C rather than C++)?

Thanks in advance.

Diego.

0 Kudos
876 Views
converse
Senior Contributor V

While it is possible to use C++ with the LPC11xx family, in reality, you will be programming in a slightly better C as so many of the useful features of C++ are really hungry for memory - both code (flash) and heap/stack (RAM). The 11C24 has just 32k of flash and 8k of ram. Also, although FreeRTOS can be pretty small, depending on features you are using, you are going to really struggle to use both C++ and any RTOS with such a small amount of memory. I would certainly recommend using an RTOS, and FreeRTOs is as good as any, I would not recommend C++ with this device.

Having said that, you may want to read this article on Embedded.com:

Modern C++ in embedded systems – Part 1: Myth and Reality | Embedded