This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: short pointers (32 bit) in 64 bit apps
On 05/19/2010 09:54 AM, Reza Roboubi wrote:
> Nicholas Sherlock wrote:
>> On 19/05/2010 3:58 p.m., Reza Roboubi wrote:
>>> Do you know what it takes to do it? How much work for a newcomer to get
>>> up to speed with gcc? (Maybe this should go to the developer list?)
>>
>> You would need to write a memory allocator which divides the address
>> space into 4GB (32-bit pages). Then you could create a new malloc
>> routine which has an extra argument to allow you to allocate memory
>> from within a specified 4GB page. That way you can make all of your
>> allocations for a given data structure lie within the same region.
>
> Since we are trying to _compress_ these structs in the first place
> malloc'ing them individually is pointless anyway. We should probably
> have some sort of custom (fixed size) allocator.
>
> <SIDE-NOTE>
> Quote from git source code: "The standard malloc/free wastes too much
> space for objects, [...]"
> </SIDE-NOTE>
>
> Really, this whole thing is for people who care about scaling something
> specific and don't mind doing sbrk and mmap when they need to. So the
> main change is a C language extension (nothing glibc/library related.)
>
> Essentially, you would want a pointer type modifier:
>
> struct list {
> struct list short * next;
> };
>
>>
>> Then you can add the top 32-bits to pointer addresses within your data
>> structure before you attempt to dereference them.
>
> That's the point: not having to do this manually.
I don't see the point of changing the language. Define a custom allocator
and store the pointers in uint32_t variables. C++ makes this very easy:
see below.
Andrew.
#include <cstdint>
#include <cstdio>
template<class T> class shortptr
{
uint32_t the_ptr;
public:
T& operator*()
{
return *(T*)the_ptr;
}
shortptr(T *p)
{
the_ptr = (uint32_t)(uintptr_t)p;
}
};
int foo (shortptr<int> p)
{
return *p;
}
int a = 99;
int
main ()
{
shortptr<int> p = &a;
int m = foo (p);
printf ("%d %d\n", m, sizeof p);
}