www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - allocated object address as high as 46th bit (i.e in the 131072 GB

reply mw <m g.c> writes:
https://dlang.org/library/core/bitop/bsr.html

I'm trying to find out allocated object's address' space:

```
import std.stdio;
import core.bitop;

void main() {
   const size_t ONE_G = 1 << 30;
   char[][128] ptrs;
   foreach (i, ref ptr; ptrs) {
     ptr = new char[ONE_G];
     if (ptr is null) {
       break;
     }
     writeln(i, ": ", bsr(cast(size_t)ptr.ptr));
   }
}

```

I tried on a few 64-bit machines (all of them have less than 
128GB memory), and the result are about all the same:

```
$ uname -m
x86_64

$ ./bit_op
0: 46
1: 46
2: 46
3: 46
4: 46
5: 46
6: 46
7: 46
8: 46
9: 46
10: 46
Killed
```

What puzzled me is that the highest set bit of the allocated 
address are all 46! i.e in the in the 2^47 ~= 131072 GB range!

I know this could be an OS thing, but just wonder if anyone can 
give me some explanation?

Thanks.
Oct 08 2023
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
As far as I'm aware, no cpu that you can get ahold of support more than 
48bit of address space at the hardware level.

There is simply no reason at this time to support more, due to the fact 
that nobody has implemented anywhere near that maximum.

Also worth noting, the address a block of memory is, has no relation to 
the hardware. A kernel will instruct the cpu to map it wherever it 
pleases per process.
Oct 08 2023
parent reply mw <m g.c> writes:
On Monday, 9 October 2023 at 05:57:47 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 As far as I'm aware, no cpu that you can get ahold of support 
 more than 48bit of address space at the hardware level.

 There is simply no reason at this time to support more, due to 
 the fact that nobody has implemented anywhere near that maximum.

 Also worth noting, the address a block of memory is, has no 
 relation to the hardware. A kernel will instruct the cpu to map 
 it wherever it pleases per process.
Thanks for the info. I'm surprised that kernel set virtual space that high.
Oct 08 2023
parent Jerry <labuurii gmail.com> writes:
The reason high bits are often set is because an address layout 
is actually 4 indicies into the page table and a page byte 
offset. So all the way to bit 48 there is index info the cpu uses.
Oct 11 2023