Understanding how Vectors work in C++ (Part-2): What happens when you initialize a vector?

In the last blog post, I realized there were a lot of methods inherited from the base struct _Vector_base_ and _Vector_impl_data. Instead of directly going to the source code of these structs, I’ll go through their methods and objects by explaining what happens when we initialize a vector. That is, we will start from calling a vector constructor and then see how memory is allocated. If you haven’t looked at the previous blog post, please take a look here. I want to be thorough with the blog post, so I’ll divide this into multiple posts. By the end of this post, you’ll go through the following structs: ...

April 26, 2020 · 7 min · Kushashwa Ravi Shrimali

Understanding how Vectors work in C++ (Part-3): Diving deep into member functions of vectors

In this blog, we’ll continue diving deep into the source code of Vector Containers in GCC compiler. Today, we will be discussing some of the most commonly used methods of vectors, and how they are implemented. Before we start, if you haven’t looked at the previous blogs in the C++ series, please take a look here. If you are already familiar with memory allocation in vector containers and vector’s base structs, then you can skip reading the previous blogs and continue here. If not, I suggest you reading them. ...

April 26, 2020 · 7 min · Kushashwa Ravi Shrimali

Understanding how Vectors work in C++ (Part-1): How does push_back work?

This blog is focused to explain how vectors work in the backend, and we’ll specially look at push_back method of the vector container. Looking at the source code helps to understand the implementation, and how vectors can be used efficiently. Vector Containers are type of sequenced containers in C++ commonly uses as a better alternative of arrays. They are also known as dynamic arrays, and as the term suggests - it’s one of the advantages they hold over native arrays in C++. You might have heard of Standard Library containers like vector, set, queue, priority_queue before. They all implement methods defined by the Container Concept. ...

April 18, 2020 · 7 min · Kushashwa Ravi Shrimali