• Where did the heap memory that I just freed go?

    Heap memory allocation via new and delete (or malloc or free for C) are unavoidable for more complex, large scale programs. However, it is a common misconception that free/delete will actually free the memory back to the operating system for other processes to use.

    This is because there are actually two different types of memory allocation happening behind a malloc/new call. The first type, reserved usually for smaller allocations (less than 100 kb) uses sbrk(), which is a traditional way of allocating memory in UNIX – it just expands the data area by a given amount. The second type uses mmap() to allocate memory for larger chunks of memory. mmap() allows you to allocate independent regions of memory without being restricted to a single contiguous chunk of virtual address space. A memory mapped region obtained through mmap() upon unmapping will immediately release the memory back to the OS, whereas sbrk() will keep the released memory within the process for future allocations.

    Read more
  • Type Erasure vs Polymorphism

    C++ templates are useful constructs to reduce code bloat (I think of them as fancy copy and paste) without any performance overhead at run-time. However, to use them effectively might require some practice. One issue I recently ran into while working with templates is the following:

    Suppose I have a generic class Foo<T> that takes a template argument, I need to place Foo<T> in a container to be iterated upon or to be looked up later. However, I might have multiple instantiations of Foo<T> of different types (i.e. int, float, double, bool), this makes it hard to use STL containers since these containers require the elements to be of a single type.

    Read more
  • Hello World

    This is the obligatory “Hello World” post.

    After various attempts to use Wordpress, Vue, React, I’ve decided to just switch to Github pages (Jekyll). The setup was fairly painless:

    • The official Github pages guide was very helpful
    • To re-direct my custom domain (bolu.dev) to the Github pages, I followed Hossain Khan’s guide here: https://medium.com/@hossainkhan/using-custom-domain-for-github-pages-86b303d3918a

    The main advantage of moving to Github pages is the ease of setup and migration should I need to do so in the future. There’s no database, almost no-setup, and I can make use of standard git workflows. The posts are in markdown so I can work on it piece-meal whenever I want. Looking forward to see if this motivates me to write more.

    Read more