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

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

In what ways do C++ exceptions slow down code when there are no exceptions thown?

There is a cost associated with exception handling on some platforms and with some compilers. Namely, Visual Studio, when building a 32-bit target, will register a handler in every function that has local variables with non-trivial destructor. Basically, it sets up a try/finally handler. The other technique, employed by gcc and Visual Studio targeting 64-bits, … Read more

Import package.* vs import package.SpecificType [duplicate]

Take a look at the java API, and you’ll see many classes and interfaces with the same name in different packages. For example: java.lang.reflect.Array java.sql.Array So, if you import java.lang.reflect.* and java.sql.* you’ll have a collision on the Array type, and have to fully qualify them in your code. Importing specific classes instead will save … Read more

How much overhead does SSL impose?

Order of magnitude: zero. In other words, you won’t see your throughput cut in half, or anything like it, when you add TLS. Answers to the “duplicate” question focus heavily on application performance, and how that compares to SSL overhead. This question specifically excludes application processing, and seeks to compare non-SSL to SSL only. While … Read more