views:

184

answers:

4

Hello!

We know that in 64bit computers pointers will be 8bytes, that will allow us to address a huge memory. But on the other hand, memories that are available to usual people now are up to 16G, that means that at the moment we do not need 8 bytes for addressig, but 5 or at most 6 bytes.

I am a Delphi user.

The question (probably for developers of 64 bit compiler) is:

Would it be possible to declare somewhere how many bytes you would like to use for pointers, and that will be valid for the whole application. In case that you have application with millions of pointers and you will be able to declare that pointers are only 5 bytes, the amount of memory that will be occupied will be much lower. I can imagine that this could be difficult to implement, but I am curious anyway about it.

Thanks in advance.

+4  A: 

Actually, it wouldn't save memory. Memory allocations have to be aligned based on the size of what you're allocating. E.g., a 4 byte section of memory has to be placed at a multiple of 4. So, due to the padding to align your 5-byte pointers, they'd actually consume the same amount of memory.

Sam Dufel
I don't think that they have to be aligned. Alignment "just" increases the performance and is required for a few SSE instructions.
CodeInChaos
In 64bit mode, alignment is far more important than in 32bit. Not aligning data (and code) in memory can have significant impact, not only on performance, but also on the ability to properly handle parallel computing. If an entity straddles an alignment boundary, it can cause memory tearing.
Allen Bauer
On some processors, @Code, memory really does need to be aligned. It's not just for performance or parallel computing; the CPU simply **will not accept** unaligned memory.
Rob Kennedy
+4  A: 

A million 64-bit pointers will occupy less than eight megabytes. That's nothing. A typical modern computer has 6 GB of RAM. Hence, 8 MB is only slightly more than 1 permille of the total amount of RAM.

Andreas Rejbrand
+2  A: 

Remember actual OSes don't let you use physical addresses. User processes always use virtual addresses (usually only the kernel can access physical addresses). The processor will transparently turn virtual addresses into physical addresses. That means you can find your program uses pointers to virtual addresses large enough that they don't have a real address counterpart for a given system. It always happened in 32 bit Windows, where DLLs are mapped in the upper 2GB (virtual process address space, always 4GB), even when the machine has far less than 2GB of memory (actually it started to happen when PC had only a few megabytes - it doesn't matter). Thereby using "small" pointers is a nonsense (even ignoring all the other factors, i.e. memory access, register sizes, instructions standard operand sizez, etc.) which would only reduce the virtual address space available. Also techniques like memory mapped files needs "large" pointers to access a file which could be far larger than the available memory.

ldsandon
+5  A: 

There are other uses for the excess precision of 8-byte pointers: you can, for example, encode the class of a reference (as an ordinal index) into the pointer itself, stealing 10 or 20 bits from the 64 available, leaving more than enough for currently available systems.

This can let the compiler writer do inline caching of virtual methods without the cost of an indirection when confirming that the instance is of the expected type.

Barry Kelly
This coming from you makes me wonder: is this something that will be implemented/is being considered for Delphi64?
PhiS
No, it's usually only useful in JIT compilers, because the obvious implementation of inline caching (caching meaning it stores state) requires rewriting the call site, and Delphi for 64-bit is fully compiled at compile time, and not using a JIT compiler. It is however sometimes used in Java virtual machines; I think Hotspot does it.
Barry Kelly
"Behind Windows x64’s 44-bit Virtual Memory Addressing Limit"http://www.alex-ionescu.com/?p=50
ldsandon