#1 2019-11-09 21:28:01

DKA
Member
Registered: 2016-07-05
Posts: 39

TSynDictionary FindAndCopy strange behaviour

Hello,

I'm facing a TSynDictionary strange behaviour :

The code below works as expected...
-----------------------------------------------------
  D:=TSynDictionary.Create(...);
  P.I :=1119; P.J:=2220;
  Setlength(Tuile,2);
  Tuile[0].Nom := 'Toto';
  Tuile[0].Coordonnees := 'gggg';
  Tuile[1].Nom := 'Titi';
  Tuile[1].Coordonnees := 'lll';
  D.Add(P,Tuile) ;
  D.FindAndCopy(P,Tuile2);
  D.Free;
-------------------------------------------------------
Now, I've add a "CreateAndFillPrepare.." + While FillOne ... begin end;

------------------------------------------------------
  D:=TSynDictionary.Create(...);
  LienTuile:=TSQLXXX.CreateAndFillPrepare(...);
  while LienTuile.FillOne do
  begin
    .....Some code....
    Setlength(Tuile,..)
    .....Some code....
    D.Add(P,Tuile);      //P is the last inserted
    D.FindAndCopy(P,Tuile2);  //>>>This works as expected
    ....
    D.FindAndCopy(R,Tuile2);  //>> This still works as expected for some iteration only. After some iteration, it stop to work (Tuile2 is unassigned)
  end;
   
------------------------------------------------------------------ 

  Some idea about what is wrong?


Edit: It's look like it depends on the number of keys. I will investigate more and come back with more information.
Edit2 : The more I investigate the less I understand. It's look like memory leak.
When I do this:
        D.FindAndCopy(P,ZGDeTuile2); //P is the last inserted : It works always
        D.FindAndCopy(R,ZGDeTuile2);//R is the first inserted. It works at the beginning, and then after some iteration, doesn't work anymore.
So, I corrected the initial post. Sorry for that.

I saw in this forum the slice method but I didn't understand how and when to use it...

Last edited by DKA (2019-11-10 17:19:49)

Offline

#2 2019-11-11 16:41:25

DKA
Member
Registered: 2016-07-05
Posts: 39

Re: TSynDictionary FindAndCopy strange behaviour

Hello,

Finally I found the issue was the key structure. I changed it from

   tDicInteger  = {$ifdef NOVARIANTS}integer{$else}variant{$endif};
   tDicKey =
      packed Record
        I,J : tDicInteger;
      End;

to

tDicKey = RawUTF8;  //I will merge I and J to obtain a unique string.

And that works as expected now. This is an acceptable workarround  for me.

I still don't know why it was not working before.

An other point was : D.Count was not equal to the number of D.Add (with each key unique) but the number of distinct I value.

Offline

Board footer

Powered by FluxBB