0

I have few doubts regarding the memory management in a x86_64 Linux Operating System.

  1. If I allocate an array of 2000 bytes (statically - arr[2000]; or dynamically - malloc(2000);) from my user space code, are these going to be a contiguous memory in physical memory?

  2. If I allocate memory (same above example, statically - arr[2000]; or dynamically - malloc(2000);) will there be a page table updation to map to these 2000 bytes in physical memory, so that the future references to these memory addresses can be found from the Page Table Entry?

Franc
  • 319
  • 9
  • 28

1 Answers1

0

1) Very unlikely. Its possible that "your" malloc() might seem to produce the result but you cannot rely on it.

What you would want to do is malloc(4000) and then have two pointers. One to the malloc and the other at pointer1+2000.

Be careful that when you free(pointer1) that you also nullify pointer2.

2) Not until you reference a byte within the area.