C++ on Small-Footprint Microcontrollers

后端 未结 6 2200
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 00:39

It seems to me people consistently shy away from, or rather vehemently oppose the use of, C++ on microcontrollers, but I can\'t for the life of me figure out why. If you sta

6条回答
  •  长情又很酷
    2020-12-05 01:21

    For "small footprint" where I would be concerned is code bloat. If your code needs to reside in a small piece of hardware, an instance of the template class

     std::vector
    

    has its own set of instructions, seperate from

     std::vector
    

    So every time you create a new kind of vector, the compiler effectively copy-pastes the code to create the new class, with its own set of functions, duplicating every instruction. If you have constraints on the amount of memory to store instructions, this could become problematic very fast. Its become problematic for people on non Embedded systems.

    In terms of runtime performance, though, I think you don't have much to worry about. In some cases, such as sorting, C++ outperforms C.

提交回复
热议问题