is there a tFIFO already built in to Free Pascal lazarus / 21-General ---------------------------------------------------------------------- mas steindorff · 2022-04-10 00:31 I need to do some quick stats on some runtime arrays of numbers,  some integer, some doubles.  I can use the Mean(), MinValue() and MaxValue() calls to give me 90% of what I need so now I'm  looking for a quick way to generate the different arrays these functions will work on. I'll be using the arrays as a FIFO.  These FIFO lengths will be changeable at runtime with numbers flowing though the 30+ FIFOs at about 500/second. I've done this task so many times before that I'm thinking of just making it into a class/object but wanted to check to see if this is already part of Free pascal, just under a different name or perhaps part of generics. Thanks MAS ---------------------------------------------------------------------- Renat.Su · 2022-04-10 02:31 TQueue from GQueue unit or TDeque from GDeque unit? ---------------------------------------------------------------------- mas steindorff · 2022-04-10 03:11 Thanks. I looked at that and saw it was a descendent of TOrderedList. the later does not manage the list memory or in my case, the array of double's memory.  I believe MinValue() and the others need continues memory in order to work. From what I can tell, the elements of TOrdederlist  do not need to be continues.  TQueue.free will not free the array either, just it's own pointers. Have I missed something? I was hoping to avoid the memory allocate and dispose task as I can not guaranty my  .free operation will be called. ---------------------------------------------------------------------- PascalDragon · 2022-04-10 14:03 You should be able to use Generics.Collections.TObjectQueue<>. ---------------------------------------------------------------------- avk · 2022-04-11 07:23 TQueue from Generics.Collections (and, accordingly, TObjectQueue) has a rather unpleasant non-obvious feature: when elements are added to a non-empty queue, its capacity constantly increases. For example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Test;var  Queue: specialize TQueue;  I, J: Integer;begin  Queue := specialize TQueue.Create;   for I := 0 to 15 do    Queue.Enqueue(I);  for I := 1 to 10000 do    begin      for J := 1 to 15 do        Queue.Dequeue;      for J := 1 to 15 do        Queue.Enqueue(J);    end;   WriteLn(Queue.Capacity);  Queue.Free;end;  Given the fact that there are never more than 16 elements in the queue at one time, what value do you expect to see? The correct answer is 207382, at least in my version of Generics.Collections. ---------------------------------------------------------------------- AlexTP · 2022-04-11 07:26 Interesting, it looks like a bug... ---------------------------------------------------------------------- avk · 2022-04-11 09:40 It could said it's a bug, but it seems that this behavior stems directly from its current design. ---------------------------------------------------------------------- AlexTP · 2022-04-11 11:42 No, Capacity prop must be not too big, (it much increase only when really needed). ---------------------------------------------------------------------- marcov · 2022-04-11 11:45 Delphi prints "16" ---------------------------------------------------------------------- AlexTP · 2022-04-11 12:18 I am sure it is a bug; reported to https://gitlab.com/freepascal.org/fpc/source/-/issues/39662 ---------------------------------------------------------------------- mas steindorff · 2022-04-11 22:38 thanks avk for checking this.  I was also getting some bad values but had not gotten as far as you. I'm also finding the help page for Mean() https://www.freepascal.org/docs-html/rtl/math/mean.html supports PInteger, but this is not true for my version of the complier (2.0.0 and FCP 3.0.4). Can someone point me to the change log where this support was added?  Thanks ---------------------------------------------------------------------- egsuh · 2022-04-12 03:15 I think you are using following method already, but I do not feel much inconveniences. Any other issue? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Tftpmain.Button1Click(Sender: TObject);var   arr: array of integer;begin   arr := [1,2,3,4,9];   showmessage(FloatTostr(Mean(arr))); // 3.8   delete(arr, 0, 1);   showmessage(FloatTostr(Mean(arr))); // 4.5   arr += [0,0];   showmessage(FloatTostr(Mean(arr))); // 3end; ---------------------------------------------------------------------- mas steindorff · 2022-04-12 06:31 since my array is a FIFO that only takes up part of the array's memory, I need the Mean(PInteger , count) version of the Mean() to limit it's range but it only exist on the help page. so I just wrote my own .... and then I decided to rewrite as a "generic" class (no types defined until it is used).  Tarray ... This is giving me different issues but is giving my mind a good workout.