In C++, is it possible to create an array of a specific size (such as short array[2048]) which begins at a specific address, such as 0x1000?
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.
Short answer: No.
In non-embedded systems (for which I’ll limit my answer to) the user address space is a virtual address space. Meaning that even if you get a pointer which points to 0x1000 that is not the physical location of your allocated data in the physical memory map. So, since the system hides physical addresses from you – you can’t request a specific physical address. Virtual addresses however, are adiffernet story…
Having understood that there is no guarantee that pointing to 0x1000 will actually mean that you are pointing to the physical address 0x1000, in Linux you can use the function
mmap()and its Windows counterpartVirtualAlloc()to request allocation to a specific virtual address. Of course these functions are not guaranteed to work (for instance, if the virtual address you are requesting is already mapped or if it is system “reserved”).