[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 64 bit->48 bit pointer hacks...



On Mon, Oct 03, 2005 at 08:49:13AM -0400, Dale E. Martin wrote:
> > The current generation AMD64 MMUs can only handle 64-bit pointers in
> > which the high-order 17 bits are all the same (40 bits of information).
> 
> I was mulling this over the other day...  Say I've got a string class that
> looks like this:
> 
> class string {
>   class shortString {
>     char flag;
>     char [7] smallString;
>   };
> 
>   class {
>     union {
>       char *ptr;
>       shortString;
>     } shortStringOrPtr;
>   } data;
> };
> 
> Is there some magic value I can write into "flag", that in combination with
> the understanding of how 64 bit pointers get truncated down to 48 bit
> virtual addresses that will allow me to store either a 7 byte string or a
> char * in the same space?

I don't think pointers are truncated until you try to use them as a
memory address.  Until then it is just some random 64bit value.  Given
you are not supposed to pick your own addresses (malloc and company does
that) you as a user application should never need to know that pointers
are limited to some number of bits.  No reason you should care.  You
only care if the system tells you that malloc failed because the system
was out of ram, or your memory space can't get any bigger (the second
one seems very unlikely to happen on 64bit systems any time soon).

Len Sorensen



Reply to: