0

Today I noticed that I suddenly spent about 38 bytes to nowhere. I was examining changes in the code.

Finally I realized that this significant change was made by adding virtual to a method. I started experimenting with virtual adding it in different places. Sometimes it takes 8 bytes, sometimes, just 2.

For my upset, I can’t predict how much RAM I will spend next time. Anybody knows how it works?

  • It all depends how you use it and what your code is doing. Not only does more information need to be stored for looking up function addresses (the "vtable"), but also compiler optimizations will be affected. This is not something you, as a human, can predict. – Majenko Feb 28 at 16:49
  • @Majenko , In this particular case, I have not used this method yet, however, virtual took 38 byte right away. Does it mean that compiler extends virtual table by some big portion? – zhekaus Feb 28 at 16:57
  • gcc can't optimize virtual methods. they always stay, if the class is is used – Juraj Feb 28 at 17:02
  • @Juraj Thanks for info. However, I asked another question. – zhekaus Feb 28 at 17:06
  • @Juraj, that looks like the answer to the question – jsotola Feb 28 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.