How to avoid memory loss on 64-bit pointers

I look forward to some high-level tips on how to approach the design that I am about to take.

A simple approach to my problem will lead to millions and millions of pointers. On a 64-bit system, these are presumably 64-bit pointers. But as for my application, I don’t think I need more than a 32-bit address space. However, I would like the system to use 64-bit processor arithmetic (assuming that this is what I get while working on a 64-bit system).

Further background

I implement a tree-like data structure where each "node" contains an 8-byte payload, but also needs pointers to four neighboring nodes (parent, left-middle, child, On a 64-bit system using 64-bit pointers, this amounts to 32 bytes only to bind the 8-byte payload to the tree - "overhead binding" 400%.

The data structure will contain millions of these nodes, but my application will not need a lot of memory, so all these 64-bit pointers seem wasteful. What to do? Is there a way to use 32-bit pointers on a 64-bit system?

I reviewed

  • Saving the payloads in the array in such a way that the index implies (and implies) the "tree address", and the neighboring values ​​of this index can be calculated using simple arithmetic at this index. Unfortunately, this requires me to size the array according to the maximum depth of the tree, which I do not know in advance, and this will probably entail even more overhead due to empty node elements at lower levels, because not all branches the tree goes to the same depth.

  • , , . AFAIK , node , . , ( ), . .

  • , 32 , , , 32 . . , , 4 , . , , ( ) (Windows, Linux, OSX).

  • 64- this 64- , , int32_t ( , ). node , this.

? ( ), , , 2 , 2 ? ?

+4
4

2 4 , , . int32_t neighborOffset = neighborIndex - thisIndex. *(this+neighborOffset). / 2, 4.

+3

Linux ( ) x32 ABI. IMHO, .

, ( std::vector ++), static . , , . , §2, static , .

( , , , )

+3

, 64- 64- , . ++ .

: sizeof(double*) sizeof(int*).

: ++.

, .

0

(2), , "". , 4 , , node 4 .

node addr index addr & -(1UL << 32) + index.

"" , "". , index , (node_address, index) (, , ). , node , .

"" 1 , , 32- 2 ^ 31 ( , 2 ^ 31 ).

(, , ) 4 , , node - .

, , "" . , , node N-, N-, . , , , ..

, , mmap ( , ) - hint , , - . , , . , : , 2 ^ N-, "" , , N will always be zero, so with a 32-bit index you could actually save 2 ^ (32 + 5) = 2 ^ 37 nodes if you knew that they were 32-byte aligned.

These tricks are really possible only in 64-bit programs with a huge amount of virtual address space, so the 64-bit method gives and also removes.

0
source

Source: https://habr.com/ru/post/1614579/


All Articles