0

I'm new to learning about low level constructs and have a simple question about how they work.

My understanding is that if I have a piece of code

int* arr = new int[100000000];

this will be a section of memory allocated on the heap of main memory.

Let's say I then have to code process the array (e.g. find minimum value).

Does the CPU fetch the 100000000 values from main memory when it needs to process each one (e.g. for comparison <)?

A diagram would help :)

  • Yes, CPUs have to fetch data from memory to work on it. In chunks of whole cache lines, of course, but yes memory bandwidth is a bottleneck for simple loops over huge arrays. (There's even a name for it: the Von Neumann bottleneck https://en.wikipedia.org/wiki/Von_Neumann_architecture#Von_Neumann_bottleneck) – Peter Cordes Aug 22 '20 at 02:47
  • Go read [What Every Programmer Should Know About Memory?](https://stackoverflow.com/q/8126311). This question seems either too trivial (a simple yes) or too broad (needs a few textbook chapters of computer architecture basics), so closing as a duplicate; go read that article; it fully answers how CPUs access memory. – Peter Cordes Aug 22 '20 at 02:47

0 Answers0