mohet01
asked on
Array in beta
Hello pma
If i say in c program
Char a[10];
We know that virtual addresses are anyways contiguous
But What about physical addresses,
Will each element of a takes 4 bytes ?
Sham
If i say in c program
Char a[10];
We know that virtual addresses are anyways contiguous
But What about physical addresses,
Will each element of a takes 4 bytes ?
Sham
In 'C', each element will take up sizeof(char) bytes and as far as the program knows, they will be contiguous. Virtual to physical translation is done invisibly outside of the C program. It would be unusual for an array or 10 or 20 bytes to cross a physical address boundary.
ASKER
Hello
My query is, can we infer that these 10 elements are stored in contiguous physical addresses?
Sham
My query is, can we infer that these 10 elements are stored in contiguous physical addresses?
Sham
ASKER
Hello
I mean do does compiler say something to mmu that array elements should be stored in 10 contiguous physical addresses ?
Sham
I mean do does compiler say something to mmu that array elements should be stored in 10 contiguous physical addresses ?
Sham
No, compilers and the programs don't normally talk to the hardware at all. The program requests memory from the operating system under OS's like Windows and Linux or Unix. The operating system handles all the details of memory management. The memory will appear to the program like the elements are in contiguous addresses.
ASKER
Hello
It means arrays are not allocated contiguously in physical memory then why text books say array is allocated contiguously
What is the advantage of using array if array is not allocated contiguously in physical memory?
Sham
Sham
It means arrays are not allocated contiguously in physical memory then why text books say array is allocated contiguously
What is the advantage of using array if array is not allocated contiguously in physical memory?
Sham
Sham
The textbook is a simple description of what happens. And it is good enough if you are just starting in programming. To you as a programmer, it will always appear to be allocated contiguously and that's all you need to know at this point. You have many other things to learn about before you get to the real differences between virtual and physical memory. In fact most programmers never ever need to know about it.
ASKER
Hello
ya am going computer architecture classes now,
But atleast I need to know, are we really having the advantage of using arrays If it is really not allocating memory contiguously in physical ram.
What so special about arrays if it is not allocating contiguously in physical ram?
Sham
ya am going computer architecture classes now,
But atleast I need to know, are we really having the advantage of using arrays If it is really not allocating memory contiguously in physical ram.
What so special about arrays if it is not allocating contiguously in physical ram?
Sham
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect
ASKER
1) each element takes 4 bytes, correct?
2) does array concept enforce compiler to store these 10 elements in 10 contiguous physical addresses?
Sham