jeudi 4 janvier 2018

Will std::array template instances use more flash memory?

I have a micro-controller that does not have an MMU, but we are using C and C++.

We are avoiding all dynamic memory usage (ie. no new SomeClass() or malloc()) and most of the standard library.

Semi-Question 0:

From what I understand std::array does not use any dynamic memory so its usage should be ok (It is on the stack only). Looking at std::array source code, it looks fine since it creates a c-style array and then wraps functionality around that array.

The chip we are using has 1MB of flash memory.

Question 1:

I am worried that the use of templates in std::array will cause the binary to be larger, which will then potentially cause the binary to exceed the 1MB of flash memory limit.

I think if you create an instance of a std::array< int, 5 >, then all calls to functions on that std::array will allocate a certain amount of flash memory, lets say X bytes of memory.

If you create another instance of std::array< SomeObject, 5 >, then call functions to that std::array, will each of those functions now be duplicated in the binary, thus taking up more flash memory? X bytes of memory + Y bytes of memory.

If so, do you think the amount of non-volatile flash memory consumed will be of concern?

Question 2:

In the above example, if you created a second std::array< int, 10 > instance, would the calls to functions also duplicate the function calls in flash memory? Even though both instances are of the same type, int?

Thanks!

Aucun commentaire:

Enregistrer un commentaire