[fpc-pascal] How to avoid Copy
Wayne Sherman
wsherman at gmail.com
Mon Jan 1 16:51:26 CET 2024
On Mon, Jan 1, 2024 at 6:14 AM Hairy Pixels wrote:
> > On Jan 1, 2024, at 3:50 PM, Michael Van Canneyt wrote:
> > You can't optimize that. As said, a generic is convenient but slow.
>
> I don't know about that. Like was mentioned the enumerator needs to return a
> pointer, preferable without ^ so it feels like a record and only use that in the for-in
> scope. You can kind of do that yourself but it's cumbersome to maintain and
> missing from the RTL (maybe for this reason).
Modern Pascal compilers already do this for certain types and pass by
reference parameters. For example, AnsiString variables and variables
of type class are handled internally as pointers, but manipulated
opaquely without explicit pointer notation. A record passed as a var
or constref parameter is internally a pointer, but does not require
the code writer to handle it explicitly as such.
More information about the fpc-pascal
mailing list