From the course: Faster Python Code

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Tracing memory allocations

Tracing memory allocations - Python Tutorial

From the course: Faster Python Code

Tracing memory allocations

- [Instructor] Sometimes you'll hear people talking about memory leaks and memory efficient programs. How is memory connected to program runtime? There is data in a program. Numbers, lists, objects, et cetera. These are stored in the computer memory, known as the heap. Every time we create a new object, we need to allocate storage for it and this operation takes time. This is one reason for why we care about memory allocation. Another reason is that accessing memory in modern computers is done in layers. We have the CPU, and then we have L1 and L2 caches. Then we have the memory. And the access times are very different. Accessing layer 1 cache is about 0.5 ns, while accessing the main memory is 100 ns. Every time we try to access a piece of data, the CPU will first try to fetch from the cache, then from main memory. Difference, also known as latency, is huge. If we keep our data small, there's a good chance it will fit…

Contents