Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TQueue<TBytes> data overwriting



Permlink Replies: 7 - Last Post: Apr 13, 2017 12:12 PM Last Post By: Remy Lebeau (Te...
Achim Strauch

Posts: 13
Registered: 4/12/02
TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 7:45 AM
Hello,

I have problems with TQueue<TBytes> in Delphi Berlin and Tokyo, XE6 works as awaited. It would be greatly appreciated, if somebody check the code. Is this a bug or should I know something special about TBytes and Generics?

1. If more items were enqueued than the capacity and the capacity automatically increases, items were overwritten. At the end of the queue are empty items.

Example:

program QueueCon;
 
{$APPTYPE CONSOLE}
{$R *.res}
 
uses
  System.SysUtils, System.Generics.Collections;
 
var
  Queue: TQueue<TBytes>;
  Count: Cardinal;
 
procedure ShowQueue;
var
  Li, Lj: Integer;
  LDataArray: TArray<TBytes>;
  LOutStr: string;
begin
  WriteLn('***ShowQueue');
  LDataArray:= Queue.ToArray;
  for Li:= 0 to Length(LDataArray) - 1 do
  begin
    LOutStr:= IntToStr(Li) + ': ';
    for Lj:= 0 to Length(LDataArray[Li]) - 1 do
      LOutStr:= LOutStr + IntToStr(LDataArray[Li, Lj]) + ' ';
    WriteLn(LOutStr);
  end;
end;
 
procedure EnqueueData(ACount: Integer);
var
  Li: Integer;
  LData: TBytes;
begin
  WriteLn('***EnqueueData(' + IntToStr(ACount) + ')');
  for Li:= 0 to ACount - 1 do
  begin
    SetLength(LData, SizeOf(Count));
    move(Count, LData[0], SizeOf(Count));
    Queue.Enqueue(LData);
    Inc(Count);
  end;
end;
 
procedure DequeueData(ACount: Integer);
var
  Li, Lj: Integer;
  LData: TBytes;
  LOutStr: string;
begin
  WriteLn('***DequeueData(' + IntToStr(ACount) + ')');
  for Li:= 0 to ACount - 1 do
  begin
    LOutStr:= IntToStr(Li) + ': ';
    LData:= Queue.Dequeue;
    for Lj:= 0 to Length(LData) - 1 do
      LOutStr:= LOutStr + IntToStr(LData[Lj]) + ' ';
    WriteLn(LOutStr);
  end;
end;
 
begin
  Queue:= TQueue<TBytes>.Create;
  //Queue.Capacity:= 20;
  Count:= 0;
  EnqueueData(2);
  ShowQueue;
  EnqueueData(2);
  ShowQueue;
  EnqueueData(2);
  ShowQueue;
  DequeueData(4);
  ShowQueue;
  (*
    EnqueueData(4);
    ShowQueue;
    DequeueData(6);
    ShowQueue;
  *)
  Queue.Free;
end.


Output
Delphi XE6: Berlin and Tokyo:
***EnqueueData(2) ***EnqueueData(2)
***ShowQueue ***ShowQueue
0: 0 0 0 0 0: 0 0 0 0
1: 1 0 0 0 1: 1 0 0 0
***EnqueueData(2) ***EnqueueData(2)
***ShowQueue ***ShowQueue
0: 0 0 0 0 0: 0 0 0 0
1: 1 0 0 0 1: 1 0 0 0
2: 2 0 0 0 2: 2 0 0 0
3: 3 0 0 0 3: 3 0 0 0
***EnqueueData(2) ***EnqueueData(2)
***ShowQueue ***ShowQueue
0: 0 0 0 0 0: 4 0 0 0
1: 1 0 0 0 1: 5 0 0 0
2: 2 0 0 0 2: 2 0 0 0
3: 3 0 0 0 3: 3 0 0 0
4: 4 0 0 0 4:
5: 5 0 0 0 5:
***DequeueData(4) ***DequeueData(4)
0: 0 0 0 0 0: 4 0 0 0
1: 1 0 0 0 1: 5 0 0 0
2: 2 0 0 0 2: 2 0 0 0
3: 3 0 0 0 3: 3 0 0 0
***ShowQueue ***ShowQueue
0: 4 0 0 0 0:
1: 5 0 0 0 1:


2. If the capacity is high enough for all items I have a similar error. I dequeue some items but not all, then I enqueue new items. Items were overwritten and empty items added.

Example (same code with decommented lines):

Output Delphi XE6: Berlin and Tokyo:
***EnqueueData(2) ***EnqueueData(2)
***ShowQueue ***ShowQueue
0: 0 0 0 0 0: 0 0 0 0
1: 1 0 0 0 1: 1 0 0 0
***EnqueueData(2) ***EnqueueData(2)
***ShowQueue ***ShowQueue
0: 0 0 0 0 0: 0 0 0 0
1: 1 0 0 0 1: 1 0 0 0
2: 2 0 0 0 2: 2 0 0 0
3: 3 0 0 0 3: 3 0 0 0
***EnqueueData(2) ***EnqueueData(2)
***ShowQueue ***ShowQueue
0: 0 0 0 0 0: 0 0 0 0
1: 1 0 0 0 1: 1 0 0 0
2: 2 0 0 0 2: 2 0 0 0
3: 3 0 0 0 3: 3 0 0 0
4: 4 0 0 0 4: 4 0 0 0
5: 5 0 0 0 5: 5 0 0 0
***DequeueData(4) ***DequeueData(4)
0: 0 0 0 0 0: 0 0 0 0
1: 1 0 0 0 1: 1 0 0 0
2: 2 0 0 0 2: 2 0 0 0
3: 3 0 0 0 3: 3 0 0 0
***ShowQueue ***ShowQueue
0: 4 0 0 0 0: 4 0 0 0
1: 5 0 0 0 1: 5 0 0 0
***EnqueueData(4) ***EnqueueData(4)
***ShowQueue ***ShowQueue
0: 4 0 0 0 0: 8 0 0 0
1: 5 0 0 0 1: 9 0 0 0
2: 6 0 0 0 2:
3: 7 0 0 0 3:
4: 8 0 0 0 4:
5: 9 0 0 0 5:
***DequeueData(6) ***DequeueData(6)
0: 4 0 0 0 0: 8 0 0 0
1: 5 0 0 0 1: 9 0 0 0
2: 6 0 0 0 2:
3: 7 0 0 0 3:
4: 8 0 0 0 4:
5: 9 0 0 0 5:
***ShowQueue ***ShowQueue

Thanks in advance

--
Achim Strauch

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 4:09 PM   in response to: Achim Strauch in response to: Achim Strauch
Achim wrote:

It would be greatly appreciated, if somebody check the code. Is
this a bug or should I know something special about TBytes and
Generics?

Sounds like a bug to me. There have been other TQueue<T> bugs in the past,
not surprising to see yet another one:

Memory corruption when using XE8's TQueue with managed types
https://quality.embarcadero.com/browse/RSP-11180

TQueue<TBytes> doesn't add elements
https://quality.embarcadero.com/browse/RSP-13196

--
Remy Lebeau (TeamB)
Achim Strauch

Posts: 13
Registered: 4/12/02
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2017 1:10 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Sounds like a bug to me. There have been other TQueue<T> bugs in the past,
not surprising to see yet another one:

Thank you.

https://quality.embarcadero.com/browse/RSP-17728

--
Achim Strauch

Achim Strauch

Posts: 13
Registered: 4/12/02
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2017 1:11 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Sounds like a bug to me. There have been other TQueue<T> bugs in the past,
not surprising to see yet another one:

Thank you.

https://quality.embarcadero.com/browse/RSP-17728

--
Achim Strauch

Achim Strauch

Posts: 13
Registered: 4/12/02
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2017 1:24 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Sounds like a bug to me. There have been other TQueue<T> bugs in the past,
not surprising to see yet another one:

Thank you.

https://quality.embarcadero.com/browse/RSP-17728

--
Achim Strauch

Achim Strauch

Posts: 13
Registered: 4/12/02
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2017 1:40 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Sounds like a bug to me. There have been other TQueue<T> bugs in the past,
not surprising to see yet another one:

Thank you.

https://quality.embarcadero.com/browse/RSP-17728

--
Achim Strauch

Achim Strauch

Posts: 13
Registered: 4/12/02
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 12, 2017 4:18 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Perhaps this one is readable with nntp:

Remy Lebeau (TeamB) wrote:


Sounds like a bug to me. There have been other TQueue<T> bugs in the past,
not surprising to see yet another one:

Thank you.

https://quality.embarcadero.com/browse/RSP-17728

--
Achim Strauch

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TQueue<TBytes> data overwriting
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 13, 2017 12:12 PM   in response to: Achim Strauch in response to: Achim Strauch
Achim wrote:

Perhaps this one is readable with nntp:

Works fine.

--
Remy Lebeau (TeamB)


---
This email has been checked for viruses by AVG.
http://www.avg.com

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02