Skip to main content
j-fischer-gundlach
Associate III
April 15, 2013
Question

NEW Operator under µVision 4

  • April 15, 2013
  • 11 replies
  • 2149 views
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
    This topic has been closed for replies.

    11 replies

    dthedens23
    Associate
    April 18, 2013
    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.