[fpc-devel] Feature request/discussion - SetLengthNoInit
J. Gareth Moreton
gareth at moreton-family.com
Wed Sep 16 16:10:03 CEST 2020
I did wonder if it was possible to use an object of some kind or, I dare
say, some evil low-level manipulation of its internal structure wrapped
into a convenient function that, say, calls ReallocMem on the internal
pointer and sets the length field as normal. The trouble is, that will
be inherently unsafe on account that you can't pass an untyped dynamic
array as a formal parameter ("array of const" is, as the name implies,
an array of constants that's just a list).
I figure I could design a dynamic array class, but it will very likely
be incompatible with SetLength no matter what I try to do, and unless
I'm mistaken, it won't have the benefit of automatically gaining an
implicit clean-up blocl if used as a local variable unless there's an
automatic reference counting feature that I'm not aware of.
Gareth aka. Kit
On 16/09/2020 03:59, Ryan Joseph via fpc-devel wrote:
>
>> On Sep 15, 2020, at 10:34 PM, J. Gareth Moreton via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
>>
>> I'm willing to settle with SetLength(array, len, ... len, NoInit: Boolean = False), but of course it depends on the overall support for it, which isn't looking too promising currently!
>>
>>
> I'd rather put the time into making custom list classes perform as well as dynamic arrays. I liked the idea that FPC has it's own native "array of" syntax but it's tied to the language and not flexible enough as we learn from time to time.
>
> Two biggest things I can think of right away:
>
> 1) We have management operators now for ref counting but the code is probably not as good as with dynamic arrays (the operator calls are not inlined I know). Also I was never able to get my patch for a Move operator added and I regard this as pretty important to avoid unnecessary copies.
>
> 2) I think for the [] operator to work with arrays of records you need to return pointers and enable the "autoderef" modeswitch to avoid the deref syntax (which is how dynamic arrays always work). Are there performance implications of this or do we get the same code as dynamic arrays?
>
>
> Regards,
> Ryan Joseph
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the fpc-devel
mailing list