When you call new [] to allocate an array for N integers, is it guaranteed to be allocated sequentially in physical memory?

From my point of view, every computer program always works with virtual memory and the method of processing physical memory depends on the operating system.

I am attending an algorithm development course, and at some point it was mentioned that if the cache is infinite and one cache line has a size B, then the expected number of cache misses that would be incurred if you just wanted to scan through an array of elements Nwill beN/B

I see how this will work in theory, because we assume that the elements Nare located one after another in physical memory.

But is it really in practice? If virtual memory is allocated sequentially, does this also mean that physical memory will also be allocated sequentially?

It seems to me that in practice, assuming that Nthere is no more cache size, you will get more than N/Bcache misses if the elements Nwere not allocated sequentially in physical memory (RAM).

Perhaps I do not understand the difference between virtual memory and physical memory, I'm not sure.

+4
source share
3 answers

This is the same as you say: array elements are contiguous in virtual memory, but not necessarily in physical memory.

PC- , , ( ). . , - , .

+4

. , N/B , , , , . , , , .

, , .

, , , .

+1

. , , . , , .

0

All Articles