-
SFINAE in C++11 and beyond
As C++ coder, sooner or later you will encounter elements of meta-programming. It might be as simple a STL container. Or it might be a full blown template class that takes variadic arguments. I, myself, have also taken this journey. As I ventured deeper into meta-programming, acronyms such as CRTP, SFINAE really piqued my interest. Today, let’s talk about SFINAE.
SFINAE stands for “substitution failure is not an error”, and there has been numerous articles, stack overflow questions and blog posts on this topic:
Read more -
Go channels in Cpp, part 2
In this part 2 of the Go channel series, I will expand the
Channel<T>class we developed to support multiple elements, range for loops and asynchronous operations.Part one of this series, where we built a simple Go channel with similar synchronization behavior is available here.
Buffered channels are desirable in many parallel applications such as work queues, worker/thread pools, MCMP (multiple consumers/producers) patterns.
Read more -
Go channels in Cpp, part 1
Go channels is the de-facto synchronization mechanism in Go. They are the pipes that connect concurrent go routines. You can send values into channels from one goroutine and receive those values into another goroutine. Having channels have made writing multi-threaded concurrent programs really simple in Go. In this series, I wanted to see if it’s possible to re-create it in cpp.
Read more -
Where did the heap memory that I just freed go?
Heap memory allocation via
newanddelete(ormallocorfreefor C) are unavoidable for more complex, large scale programs. However, it is a common misconception thatfree/deletewill 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
Read moremalloc/newcall. The first type, reserved usually for smaller allocations (less than 100 kb) usessbrk(), which is a traditional way of allocating memory in UNIX – it just expands the data area by a given amount. The second type usesmmap()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 throughmmap()upon unmapping will immediately release the memory back to the OS, whereassbrk()will keep the released memory within the process for future allocations. -
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
Read moreFoo<T>that takes a template argument, I need to placeFoo<T>in a container to be iterated upon or to be looked up later. However, I might have multiple instantiations ofFoo<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. -
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