[fpc-devel] Suggestion: reference counted objects

Nikolai Zhubr n-a-zhubr at yandex.ru
Sun Sep 21 23:59:31 CEST 2014


22.09.2014 0:28, Peter Popov:
[...]
> 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.

This would look aesthetically horid at least. Somehow reminds of 
segment:offset ugliness of 8086 ;-)

Besides, thinking about a magnificent brand new pointer type, and as 
long as certain performance penalties can be tolerated, one might want 
to also consider providing some path for heap defragmentation, for the 
sake of completeness (Not that I know how to properly do it, but still 
my $0.02).

Regards,
Nikolai

>
>
> 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
>>
>
>




More information about the fpc-devel mailing list