Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ASIDE: EVERY ADDRESS YOU SEE IS VIRTUAL Ever write a C program that prints out a pointer? The value you see (some large number, often

image text in transcribed

ASIDE: EVERY ADDRESS YOU SEE IS VIRTUAL Ever write a C program that prints out a pointer? The value you see (some large number, often printed in hexadecimal), is a virtual address. Ever wonder where the code of your program is found? You can print that out too, and yes, if you can print it, it also is a virtual address. In fact, any address you can see as a programmer of a user-level program is a virtual address. It's only the OS, through its tricky techniques of virtualizing memory, that knows where in the physical memory of the machine these instructions and data values lie. So never forget: if you print out an address in a program, it's a virtual one, an illusion of how things are laid out in memory; only the OS (and the hardware) knows the real truth. Here's a little program (va.c) that prints out the locations of the main() routine (where code lives), the value of a heap-allocated value returned from malloc(), and the location of an integer on the stack: #include #include int main(int argc, char *argv[]) { printf("location of code : %p ", main); printf("location of heap : %p ", malloc (10016)); int x = 3; printf("location of stack: %p ", &X); return x; } When run on a 64-bit Mac, we get the following output: location of code : 0x1095afe50 location of heap : 0x109600800 location of stack: 0x7fff691aea 64 From this, you can see that code comes first in the address space, then the heap, and the stack is all the way at the other end of this large virtual space. All of these addresses are virtual, and will be translated by the OS and hardware in order to fetch values from their true physical locations. Explain : - how the int x=3 declaration allows the program to find the location of the stack

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions