Posts in tag

Lemires


Programmers sometimes need to trim, or remove, characters, such as spaces from strings. It might be a surprising expensive task. In C, the following function is efficient: size_t trimspaces(const char *s, size_t len, char *out) { char * init_out{out}; for(size_t i = 0; i < len; i++) { *out = s[i]; out += (s[i] != …

In an earlier blog post, I reported that the memory usage of a small byte array in Java (e.g., an array containing 4 bytes) was about 24 bytes. In other words: allocating small blocks of memory has substantial overhead. What happens in C++? To find out, I can try to allocate one million 4-byte arrays …