[fpc-pascal] Primitive Record Wrappers
Sven Barth
pascaldragon at googlemail.com
Sun Feb 21 09:29:43 CET 2016
Am 21.02.2016 03:02 schrieb "Mazola Winstrol" <mazofeifer at gmail.com>:
>
> 2016-02-20 3:24 GMT-02:00 Michalis Kamburelis <michalis.kambi at gmail.com>:
>>
>> The major problem there is that it's difficult to force it to be
>> always initialized with zeroes. Currently, a non-global variable of
>> unmanaged type can always be filled with memory garbage, as explained
>> in other thread. The trick in
>> http://blogs.embarcadero.com/abauer/2008/09/18/38869 to use interfaces
>> feels ugly, it's an over-use of the "interface" specifics in Object
>> Pascal.
>>
>
> A less "ugly" code could be to store the pointer value in an array of
bytes (TBytes). As the TBytes type is a managed type, it will always be
initialized.
The managed type isn't needed for the data (that should be stored as a
plain field to let the compiler take care of finalization), but instead
it's needed to store whether the field contains a valid value (not Null) or
not (null). For this potentially any managed type (array, string,
interface) can be used, but it might indeed be that the manual interface
approach is the fastest, because there one can avoid unnecessary locking
(it's done by the implementations of AddRef and Release) which is not the
case with arrays and strings as the reference counting routines always do
locking.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160221/1726d195/attachment.html>
More information about the fpc-pascal
mailing list