[fpc-devel] Suggestion: reference counted objects

Peter Popov ppopov99 at gmail.com
Sun Sep 21 22:28:06 CEST 2014


No, the idea is to compact an 8 byte pointer to a 4 byte one. Basically,
save memory. This would limit the accessible memory tough. Probably for a
different thread.

HOWEVER: here is another one idea. Current memory buses are 48 bit wide,
so basically a pointer can be stored in 6 bytes. It is stored in 8,
because of memory alignment issues.

So, for classes which are reference counted, store the reference count @
the highest two bytes of the class instance (which in practice is a
pointer to the VMT). This would let you ref-count up to 2^16. You need to
mask it out from the rest of the pointer when accessing VMT. No need for
additional changes to the RTTI, just mask the highest two bytes when using
the class.


Peter

On Sun, 21 Sep 2014 23:03:43 +0300, Boian Mitov <mitov at mitov.com> wrote:

> This is not true. Ref pointer is exactly the same size as non ref  
> pointer. the counter is in the instance not in the pointer to the  
> instance ;-) .
> You can study the interface implementations or the String  
> implementations they are done the same way.
>
> With best regards,
> Boian Mitov
>
> -------------------------------------------------------
> Mitov Software
> www.mitov.com
> -------------------------------------------------------
> -----Original Message----- From: Peter Popov
> Sent: Sunday, September 21, 2014 12:29 PM
> To: fpc-devel at lists.freepascal.org ; Sven Barth
> Subject: Re: [fpc-devel] Suggestion: reference counted objects
>
> Sven,
> based on your comments a bizarre thought came to me. Currently, class
> instances are pointers. What you propose will somehow create a special
> pointer type (referenced class).
>
> Should this be done, I have a request: create a 4 byte "compressed" class
> reference which expands into an 8 byte pointer type prior to usage:
> 1. Most architectures align data.
> 2. 64 bit comps align pointers on 8 byte boundaries, meaning that the 3
> leftmost bits are 0.
> 3. You could store a class pointer as a 4 byte integer and, prior to
> usage, expand it to 8 bytes a leftshift 3.
>
> In this way you will have 64GB of data available to your program and your
> pointers will occupy twice less. If, for example one uses large amount of
> pointers, this could be ... aesthetically pleasing ...
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the fpc-devel mailing list