Is there any penalty/cost of virtual inheritance in C++, when calling non-virtual base method?

There may be, yes, if you call the member function via a pointer or reference and the compiler can’t determine with absolute certainty what type of object that pointer or reference points or refers to. For example, consider: void f(B* p) { p->foo(); } void g() { D bar; f(&bar); } Assuming the call to … Read more

What is the most efficient binary to text encoding?

This really depends on the nature of the binary data, and the constraints that “text” places on your output. First off, if your binary data is not compressed, try compressing before encoding. We can then assume that the distribution of 1/0 or individual bytes is more or less random. Now: why do you need text? … Read more

Does using std::array lead to code bloat? [duplicate]

I wouldn’t worry about it. If you look at the interface of std::array<T, N>, it is very small and most member functions (basically providing wrappers for pointer manipulation) are one-liners that will be completely optimized away / inlined by any decent compiler on Release mode optimization levels. Furthermore, you don’t pay for what you don’t … Read more

C++ exception overhead

Just my 2 cents… I consult exclusively on embedded systems, most of them hard real-time and/or safety/life critical. Most of them run in 256K of flash/ROM or less – in other words, these are not “PC-like” VME bus systems with 1GB+ of RAM/flash and a 1GHz+ CPU. They are deeply embedded, somewhat resource-constrained systems. I … Read more

Overhead of a .NET array?

Here’s a slightly neater (IMO) short but complete program to demonstrate the same thing: using System; class Test { const int Size = 100000; static void Main() { object[] array = new object[Size]; long initialMemory = GC.GetTotalMemory(true); for (int i = 0; i < Size; i++) { array[i] = new string[0]; } long finalMemory = … Read more

Can placement new for arrays be used in a portable way?

Personally I’d go with the option of not using placement new on the array and instead use placement new on each item in the array individually. For example: int main(int argc, char* argv[]) { const int NUMELEMENTS=20; char *pBuffer = new char[NUMELEMENTS*sizeof(A)]; A *pA = (A*)pBuffer; for(int i = 0; i < NUMELEMENTS; ++i) { … Read more

Time measuring overhead in Java

The answer marked correct on this page is actually not correct. That is not a valid way to write a benchmark because of JVM dead code elimination (DCE), on-stack replacement (OSR), loop unrolling, etc. Only a framework like Oracle’s JMH micro-benchmarking framework can measure something like that properly. Read this post if you have any … Read more

tech