Hand-Crafted Vectors

I've been continuing my studies in computer science by implementing a vector (automatically resizing array) without using arrays.

I started with C, and wanted to get more experience with allocating/freeing memory and practicing with pointers on an array of integers. I don't use the [] operator when accessing members. I just treat the block of memory as a block of memory and do pointer math to access and iterate over elements.

Implementing a vector in C

It turned out really well even though I started off very slowly, and had to take time to set up debugging (LLDB, included in CLion) and Valgrind for checking for coding oversights and memory leaks. But that sunk cost will pay off as an investment in future development.

You can follow along with my C code on Github:

I'm currently implementing in C++ without using vectors or arrays. I ditched the raw pointer for a std::unique_ptr, and made a JVector class to make this an OO solution to encapsulate data and operations. I'm following the Google C++ Style Guide. If I missed something, let me know.

Follow along with my C++ implementations on Github:

comments powered by Disqus