Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is memory address 0x0 usable?

I was wondering... what if when you do a new, the address where the reservation starts is 0x0? I guess it is not possible, but why? is the new operator prepared for that? is that part of the first byte not usable? it is always reserved when the OS starts?

Thanks!

like image 265
Mario Corchero Avatar asked Jan 18 '13 21:01

Mario Corchero


People also ask

Is zero a valid memory address?

The memory at that address is reserved for use by the operating system. 0 - 64k is reserved. 0 is used as a special value to indicate to developers "not a valid address".

Is 0x0 null?

0x0 is just 0 written in hexadecimal notation. There is no difference between the two: 016 = 010 :) NULL is usually #define d to 0 somewhere and does the same thing.

Is 0 a valid pointer?

Using a signed integer for addresses is a little wasteful if it means that apart from the null pointer (-1 or whatever) the value space is split evenly between positive integers that make valid addresses and negative numbers that are just wasted. If any number is always representable by a datatype, it's 0.

What is the highest memory address?

The 1620 used 5-digit decimal addresses, so in theory the highest possible address was 99,999. In practice, the CPU supported 20,000 memory locations, and up to two optional external memory units could be added, each supporting 20,000 addresses, for a total of 60,000 (00000–59999).


2 Answers

The null pointer is not necessarily address 0x0, so potentially an architecture could choose another address to represent the null pointer and you could get 0x0 from new as a valid address. (I don't think anyone does that, btw, it would break the logic behind tons of memset calls and its just harder to implement anyway).

Whether the null pointer is reserved by the Operative System or the C++ implementation is unspecified, but plain new will never return a null pointer, whatever its address is (nothrow new is a different beast). So, to answer your question:

Is memory address 0x0 usable?

Maybe, it depends on the particular implementation/architecture.

like image 72
K-ballo Avatar answered Oct 14 '22 00:10

K-ballo


"Early" memory addresses are typically reserved for the operating system. The OS does not use early physical memory addresses to match to virtual memory addresses for use by user programs. Depending on the OS, many things can be there - the Interrupt Vector Table, Page table, etc.

Here is a non-specific graph of layout of physical and virtual memory in Linux; could vary sligthly from distro to distro and release to release:

http://etutorials.org/shared/images/tutorials/tutorial_101/bels_0206.gif

^Don't be confused by the graphic - the Bootloader IS NOT in physical memory... don't know why they included that... but otherwise it's accurate.

like image 34
PinkElephantsOnParade Avatar answered Oct 14 '22 00:10

PinkElephantsOnParade