How to write a large buffer into a binary file in C++, fast?

This did the job (in the year 2012): #include <stdio.h> const unsigned long long size = 8ULL*1024ULL*1024ULL; unsigned long long a[size]; int main() { FILE* pFile; pFile = fopen(“file.binary”, “wb”); for (unsigned long long j = 0; j < 1024; ++j){ //Some calculations to fill a[] fwrite(a, 1, size*sizeof(unsigned long long), pFile); } fclose(pFile); return … Read more

Storing JSON in database vs. having a new column for each key

Updated 4 June 2017 Given that this question/answer have gained some popularity, I figured it was worth an update. When this question was originally posted, MySQL had no support for JSON data types and the support in PostgreSQL was in its infancy. Since 5.7, MySQL now supports a JSON data type (in a binary storage … Read more

Inline functions in C#?

Finally in .NET 4.5, the CLR allows one to hint/suggest1 method inlining using MethodImplOptions.AggressiveInlining value. It is also available in the Mono’s trunk (committed today). // The full attribute usage is in mscorlib.dll, // so should not need to include extra references using System.Runtime.CompilerServices; … [MethodImpl(MethodImplOptions.AggressiveInlining)] void MyMethod(…) 1. Previously “force” was used here. I’ll … Read more

Why does glibc’s strlen need to be so complicated to run quickly?

You don’t need and you should never write code like that – especially if you’re not a C compiler / standard library vendor. It is code used to implement strlen with some very questionable speed hacks and assumptions (that are not tested with assertions or mentioned in the comments): unsigned long is either 4 or … Read more

How do I position one image on top of another in HTML?

Ok, after some time, here’s what I landed on: .parent { position: relative; top: 0; left: 0; } .image1 { position: relative; top: 0; left: 0; border: 1px red solid; } .image2 { position: absolute; top: 30px; left: 30px; border: 1px green solid; } <div class=”parent”> <img class=”image1″ src=”https://via.placeholder.com/50″ /> <img class=”image2″ src=”https://via.placeholder.com/100″ /> </div> … Read more