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.

  • allocated object... mw via Digitalmars-d-learn

Reply via email to