[fpc-devel] I get duplicate GUIDs under Linux

Graeme Geldenhuys graemeg.lists at gmail.com
Thu May 29 12:07:12 CEST 2008


Hi,

I'm trying to do performance testing in Firebird RDBMS using GUID's
and primary keys. I constantly got PK violations. I then wrote the
code show below to create 50,000 GUID's and add them to a StringList
(no duplicates allowed). Every time I run this I get a duplicate GUID
at iteration 1021.  My original test is supposed to create 5mil
records, but I can't get past 1000! :-(

Actual program output:

graemeg at graemeg:index_performance$ ./index_performance.elf
Duplicate value detected: {FD3DF19D-A878-F8BA-F9D1-108658451E05}
  List.Count = 1021

GUID's are supposed to be very unique! Wikipedia says something like:
Create a billion every second for 10 years or something before you
deplete the range.
So what is wrong with my code or maybe the Free Pascal implementation?

--------------------[ code ]------------------------------
procedure TMainForm.btnTestClicked(Sender: TObject);
var
  sl: TStringList;
  s: string;
  i: integer;
  d: integer;
  guid: TGUID;
begin
  sl := TStringList.Create;
  try
    try
      sl.Sorted := True;
      sl.Duplicates := dupError;
      for i := 1 to 50000 do
      begin
        CreateGUID(guid);
        s := GUIDToString(guid);
        sl.Add(s);
      end;
      writeln('Created 50,000 GUIDs');
    except
      on e: EStringListError do
      begin
        writeln('Duplicate value detected: ' + s);
        writeln('  List.Count = ', sl.Count);
      end;
      on e: Exception do
        writeln('Unknown error: ', e.Message);
    end;
  finally
    sl.Free;
  end;
end;
--------------------[ end ]--------------------------------


Changing the line that adds the GUID to the StringList by prefixing
the counter, all is fine. So I can't see a problem in my code.

   sl.Add(IntToStr(i) + s);


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list