Michael Schnell wrote:
On 10/02/2014 03:59 PM, Xiangrong Fang wrote:
, not replace TFPList with TThreadList, for simplicity and performance reason...
I don't suppose it will be possible to beat TThreadList performance by any home-brew Pascal code, which is same is not insecure.

But I looked at the source code of TThreadList,

procedure TThreadList.Add(Item: Pointer);
  begin
    LockList;
    try
      if (Duplicates=dupAccept) or
        // make sure it's not already in the list
        (FList.IndexOf(Item)=-1) then
         FList.Add(Item)
       else if (Duplicates=dupError) then
         FList.Error(SDuplicateItem,PtrUInt(Item));
    finally
      UnlockList;
    end;
  end;


where

function TThreadList.LockList: TList;
  begin
    Result:=FList;
    System.EnterCriticalSection(FLock);
  end;


There is no special optimization at all.  It simply calls
  System.EnterCriticalSection(FLock),
so performance should be JUST THE SAME as wrapping a pair of critical section enter/leave around the code ourselves.

Dennis



_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to