Is a pointer a guaranteed> specific value?

In C ++, when I do new(or even malloc), is there any guarantee that the return address will be greater than a certain value? Because ... in this project, I find it useful to use 0-1k as an enumeration. But I would not want to do this if it could be obtained so low. My only target systems are 32 or 64 bit processors with OS window / linux and mac.

Does the standard talk about pointers? Do windows or linux say something about their C runtime and what is the lowest memory address (for ram)?

-edit- I end up modifying my overload newto check if the address is above> 1k. I call std :: terminate if it is not.

+5
source share
5 answers

There is no such guarantee. You can use the layoutnew if you need very specific memory cells, but it has certain problems that you will have to work to avoid . Why don't you try using a map with an integer key that has a pointer instead? Thus, you do not have to rely on specific addresses and address ranges.

+4
source

. , Windows, , 64- ( , PAGE_NOACCESS), 0x80000000 + , , . this this MSDN.

x64 ( 47 ), , , (AMD, ).

+6

- > 0. ( , "1" ), no , , 1000. , " undefined".

+2

, ; - , ( , ).

+1

, ​​, , ..

NULL 0x0. , x86 128 "NULL-", . x64 , , , .

As for the address space reserved for the operating system, this will clearly depend on the OS. On Linux, the separation of kernel and user space is configured in the kernel, so at least 3 partitions: 1-3 GB, 2-2 GB, and 3-1 GB are common for 32-bit systems. You can find more information on kerneltrap .

+1
source

All Articles