<div dir='auto'><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Dec 29, 2023 9:50 PM, Adriaan van Os <adriaan@adriaan.biz> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Amir--- via fpc-pascal wrote:
<br>
> Hi all,
<br>
>
<br>
> I have a List of record, where the record has a WideString field.
<br>
> I have some code like the following:
<br>
>
<br>
> function check(constref v: TMyRecord; data: TListOfMyRecord): Boolean;
<br>
> var
<br>
> r: TMyRecord;
<br>
>
<br>
> begin
<br>
> Result := False;
<br>
> for r in data do
<br>
> if r.State = v.State then
<br>
> Exit(True);
<br>
> end;
<br>
>
<br>
> I call this method a lot and the CPU profiling shows a lot of cpu time
<br>
> spent on "fpc_copy_proc" (which I assume is doing the deep copy on
<br>
> records) from "TCustomListEnumerator.GetCurrent".
<br>
> I considered other alternatives like using enumerators but they all need
<br>
> a to return a record (and hence copying the widestring field).
<br>
> I can think of two solutions to get rid of the wasting(!) so much time
<br>
> on "fpc_copy_proc":
<br>
> 1) Changing the TMyRecord to TMyClass. But then I need to Create and
<br>
> Free a "lot" of objects.
<br>
> 2) Update TListOfMyRecord to TListOfPointerToMyRecord. This requires a
<br>
> "lot" of memory allocation/fragmentation.
<br>
>
<br>
> Is there a better solution?
<br>
<br>
Pass the data parameter by reference.</p></blockquote></div></div></div><div dir="auto">This means I need to have a ListOfMyRecord and a ListOfConstRefMyRecord, right?</div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">
<br>
<br>
Regards,
<br>
<br>
Adriaan van Os
<br>
</p>
</blockquote></div><br></div></div></div>