In C++, while accessing the memory with pointers, if it reaches the end of memory what happens?

10 pts.
Tags:
C++
Memory management
In C++, while accessing the memory with pointers, if it reaches the end of memory what happens?
ASKED: June 6, 2008  1:06 PM
UPDATED: June 6, 2008  6:42 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

In C++ or C, when you allocate memory using malloc or new you are asking for chunk of memory. But Compiler will always assign memory in pages. Now each page contains how many bytes of memory is configurable and system dependant. Whenever you are accessing the memory beyond your assign i.e. one page Segmentation fault will occur.

But always keep in mind for each memroy allocation, compiler never allocates one page for each allocation.

Consider
1) malloc for 100 bytes then compiler will assign one page (Consider page of 4KB)
2) malloc for 200 bytes then compiler will not asign any page for you but provide addres within same page. This is how memory is allocated by compiler.
Now if you access memory beyond your page you will get segmentation fault.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following