Linked Lists vs Arrays from a Memory Point of View

Learn key differences in the memory representation of linked lists and arrays.


We reiterate that the purpose of this chapter isn’t to teach data structures. The purpose is to practice memory allocations, pointer manipulation, and correct memory management. It just so happens that implementing linked lists is a perfect way to achieve our goal.

Now we’ll discuss a few differences between arrays and lists from a memory point of view. It’s by no means a general comparison between the two data structures. We’re focused on the memory aspect.


Arrays are continuous

We allocate arrays as a contiguous memory block. This behavior is good news because the allocation code is simple, and the cache spatial locality principle is respected.

Let’s quickly allocate an array and print the addresses of each element.

Get hands-on with 1200+ tech skills courses.