cancel
Showing results for 
Search instead for 
Did you mean: 

NEW Operator under µVision 4

j-fischer-gundlach
Associate II
Posted on April 15, 2013 at 19:55

Hello Community,

i´m having a stm32f3Discovery under the Keil´s µVision4 Compiler programming in c++.

I got to the point, where i could use the ''NEW''  operator.

To be honest, i have no idea, what is really going on. I know in principle this operator

allocates space for the given type and returns a pointer in case of success.

As long i used this on a desktop PC i didn´t care, since there ia an OS under my feet.

I mean, if i allocate space i guess this trigger the OS to ''talk'' to some kind of

memory controller if there is enough space and where it is, and also handles

the cirumstances if the memory becomes fragmented. (?)

And this is where my understanding ends when it comes to bare µC´s. Do i really have to

import a complete OS just for getting new/delete oportunities?

And what is administrating the RAM in my STM32F3 i could ''talk'' to? Would i have do

make this RAM controller by my own?

For summing up the whole scenery in one question:

What is going on in my stm32F3 if the compiler finds a ''NEW''?

yours sincerly,

Justus
11 REPLIES 11
Andrew Neil
Evangelist III
Posted on April 18, 2013 at 14:54

''The key idea is not to programm the sticks and switches with fix functions, rather than making the whole thing configurable''

You don't need  C++ to do that.

You could create a plain 'C' library of functions, so only the top-most level of your code would need to be specific to a particular product...
dthedens23
Associate II
Posted on April 18, 2013 at 20:11

Did something very similar on a big linux project.  The Constructors were passed a node to an XML configuration file.  The constructor would then configure itself and create it's children objects (passing them a node)  and, ...

you might want to design it so that at boot, it reads the configuration and builds the objects.  If you are already running, delete objects, then change configs, allocate objects, you may fail to allocate objects due to the heap fragmentation.  So when you change configs, you reboot, and somehow persist the new configuration.

The source code to new, delete, malloc(), and free() are available.  See for yourself that free() does minimal garbage collection.