as the title says, I want to know in c++, whether the memory allocated by one new operation is consecutive…
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this code, whatever size is given, the returned memory region is consecutive. If the heap manager can’t allocate consecutive memory of
size, it’s fail. an exception (or NULL inmalloc) will be returned.Programmers will always see the illusion of consecutive (and yes, infinite 🙂 memory in a process’s address space. This is what virtual memory provides to programmers.
Note that programmers (other than a few embedded systems) always see virtual memory. However, virtually consecutive memory could be mapped (in granularity of ‘page’ size, which is typically 4KB) in physical memory in arbitrary fashion. That mapping, you can’t see, and mostly you don’t need to understand it (except for very specific page-level optimizations).
What about this?
Sure, you can’t say the relative address of
data1anddata2. It’s generally non-deterministic. It depends on heap manager (such asmalloc, oftennewis just wrappedmalloc) policies and current heap status when a request was made.