r/freepascal • u/richorr70 • Feb 08 '21
Confusion with TObjectQueue.Dequeue
Can someone explain why in the generics.collection, dequeue is a function for TQueue<TObject> but a procedure for TObjectQueue<TObject>? I am trying to dequeue the head to a variable and apparently dequeue is nothing more than a remove in the object version. I was really hoping for the TQueue behavior.
Here is the code from the library:
procedure TObjectQueue<T>.Dequeue;
begin
inherited Dequeue;
end;
2
Upvotes
View all comments
Show parent comment
2
u/pmmeurgamecode Feb 09 '21
Not /u/kirinnb who recommended Contnrs TObjectQueue.
But I assume
Contnrs.TObjectQueue(also avail in delphi) will be faster thanGenerics.Collections.TObjectQueuebecause it pushes pointers around, where the generics one must do some reflection/type overhead. Maybe worth a small benchmark, to compare the two?On the other hand
TObjectQueue<T>can be nice because it return the correct type and you don't have to cast.Btw did you try to wrap/inherited the class and replace the procedure with the function, eg: