2 ms·
Most efficiency gains of imperative programming languages like C or C++ come from the compact and continguous memory layout and usage of the stack which is usua
by imtringued 9y ago
Most efficiency gains of imperative programming languages like C or C++ come from the compact and continguous memory layout and usage of the stack which is usually in the L1 cache.
In theory there would be no difference between mutating an existing memory area and allocating new memory to write to it. The number of bytes written to RAM are the same.
- lossolo 9y ago> In theory there would be no difference between mutating an existing memory area and allocating new memory to write to it. The number of bytes written to RAM are the same. It's not the same, you need to allocate new memory, if it's on the heap then (depending on your allocator/OS etc) you will be making a syscall, which means context switch, cache eviction etc.
- vvanders 9y agoThis is where understanding the difference between theory and practice is important, by its nature anything in the heap is not going to be in L1 cache. That means a difference of ~300 cycles before you can even start working with the cache line you pull from main memory.