Re: [fpc-pascal] How to avoid Copy

2024-01-02 Thread Amir--- via fpc-pascal
Thanks! On 1/2/24 22:59, Sven Barth via fpc-pascal wrote: Amir--- via fpc-pascal schrieb am Mi., 3. Jan. 2024, 07:53: Yeap! That is actually what I posted here (Feature Request) . My example allows you to access it right

Re: [fpc-pascal] How to avoid Copy

2024-01-02 Thread Sven Barth via fpc-pascal
Amir--- via fpc-pascal schrieb am Mi., 3. Jan. 2024, 07:53: > Yeap! That is actually what I posted here (Feature Request) > . > My example allows you to access it right now with the existing FPC release. Regards, Sven >

Re: [fpc-pascal] How to avoid Copy

2024-01-02 Thread Amir--- via fpc-pascal
Yeap! That is actually what I posted here (Feature Request) .  You simply need to inherit from the list class so that you can make the function public. And with a little trick you can also use it inside a for-in-loop: === code

Re: [fpc-pascal] How to avoid Copy

2024-01-02 Thread Sven Barth via fpc-pascal
Am 31.12.2023 um 04:11 schrieb Amir--- via fpc-pascal: On 12/30/23 00:20, Sven Barth via fpc-pascal wrote: Amir via fpc-pascal schrieb am Sa., 30. Dez. 2023, 08:11: On Dec 29, 2023 9:50 PM, Adriaan van Os wrote: Amir--- via fpc-pascal wrote: > Hi all, >

Re: [fpc-pascal] How to avoid Copy

2024-01-02 Thread Sven Barth via fpc-pascal
Am 01.01.2024 um 16:51 schrieb Wayne Sherman via fpc-pascal: 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

Re: [fpc-pascal] How to avoid Copy

2024-01-01 Thread Wayne Sherman via fpc-pascal
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

Re: [fpc-pascal] How to avoid Copy

2024-01-01 Thread Hairy Pixels via fpc-pascal
> 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

Re: [fpc-pascal] How to avoid Copy

2024-01-01 Thread Michael Van Canneyt via fpc-pascal
On Mon, 1 Jan 2024, Hairy Pixels via fpc-pascal wrote: On Dec 30, 2023, at 3:18 PM, Michael Van Canneyt via fpc-pascal wrote: And try to avoid "for r in data" because it will create a copy for each element in the list. This seems more like bad compiler design than anything. From the

Re: [fpc-pascal] How to avoid Copy

2023-12-31 Thread Hairy Pixels via fpc-pascal
> On Dec 30, 2023, at 3:18 PM, Michael Van Canneyt via fpc-pascal > wrote: > > And try to avoid "for r in data" because it will create a copy for each > element > in the list. This seems more like bad compiler design than anything. From the users perspective a for loop is a read-only

Re: [fpc-pascal] How to avoid Copy

2023-12-31 Thread Michael Van Canneyt via fpc-pascal
On Sun, 31 Dec 2023, Amir--- via fpc-pascal wrote: On 12/31/23 02:46, Marco van de Voort via fpc-pascal wrote: Op 31/12/2023 om 04:11 schreef Amir--- via fpc-pascal: I compiled the code with `fpc -O3 -Sd -gv -g -gl ` and ran `valgrind` on it (the output is attached). It does not look

Re: [fpc-pascal] How to avoid Copy

2023-12-31 Thread Amir--- via fpc-pascal
On 12/31/23 02:46, Marco van de Voort via fpc-pascal wrote: Op 31/12/2023 om 04:11 schreef Amir--- via fpc-pascal: I compiled the code with `fpc -O3 -Sd -gv -g -gl ` and ran `valgrind` on it (the output is attached). It does not look like there is a big difference between the Check1 and

Re: [fpc-pascal] How to avoid Copy

2023-12-31 Thread Marco van de Voort via fpc-pascal
Op 31/12/2023 om 04:11 schreef Amir--- via fpc-pascal: I compiled the code with `fpc -O3 -Sd -gv -g -gl ` and ran `valgrind` on it (the output is attached). It does not look like there is a big difference between the Check1 and Check2 but Check3 is about 20 times faster than the other two.

Re: [fpc-pascal] How to avoid Copy

2023-12-30 Thread Sven Barth via fpc-pascal
Amir via fpc-pascal schrieb am Sa., 30. Dez. 2023, 08:11: > > > On Dec 29, 2023 9:50 PM, Adriaan van Os wrote: > > Amir--- via fpc-pascal wrote: > > Hi all, > > > > I have a List of record, where the record has a WideString field. > > I have some code like the following: > > > > function

Re: [fpc-pascal] How to avoid Copy

2023-12-30 Thread Michael Van Canneyt via fpc-pascal
On Fri, 29 Dec 2023, Amir via fpc-pascal wrote: On Dec 29, 2023 9:50 PM, Adriaan van Os wrote: Amir--- via fpc-pascal wrote: > Hi all, > >  I have a List of record, where the record has a WideString field. >   I have some code like the following: >

Re: [fpc-pascal] How to avoid Copy

2023-12-29 Thread Amir via fpc-pascal
On Dec 29, 2023 9:50 PM, Adriaan van Os wrote:Amir--- via fpc-pascal wrote: > Hi all, > >  I have a List of record, where the record has a WideString field. >   I have some code like the following: > > function check(constref v: TMyRecord; data: TListOfMyRecord): Boolean; > var >   r:

Re: [fpc-pascal] How to avoid Copy

2023-12-29 Thread Adriaan van Os via fpc-pascal
Amir--- via fpc-pascal wrote: Hi all, I have a List of record, where the record has a WideString field. I have some code like the following: function check(constref v: TMyRecord; data: TListOfMyRecord): Boolean; var r: TMyRecord; begin Result := False; for r in data do if r.State

[fpc-pascal] How to avoid Copy

2023-12-29 Thread Amir--- via fpc-pascal
Hi all,  I have a List of record, where the record has a WideString field.   I have some code like the following: function check(constref v: TMyRecord; data: TListOfMyRecord): Boolean; var   r: TMyRecord; begin   Result := False;   for r in data do     if r.State = v.State then