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
      Exit(True);
end;

I call this method a lot and the CPU profiling shows a lot of cpu time spent on "fpc_copy_proc" (which I assume is doing the deep copy on records) from "TCustomListEnumerator.GetCurrent". I considered other alternatives like using enumerators but they all need a to return a record (and hence copying the widestring field). I can think of two solutions to get rid of the wasting(!) so much time on "fpc_copy_proc": 1) Changing the TMyRecord to TMyClass. But then I need to Create and Free a "lot" of objects. 2) Update TListOfMyRecord to TListOfPointerToMyRecord. This requires a "lot" of memory allocation/fragmentation.

Is there a better solution?

Best,
Amir
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to