2

I have a thread that creates objects with status info (about one per second) and adds it to a ConcurrentQuery.

query.Enqueue(new Tuple<string, DateTime>("some info", DateTime.Now));

Another tread reads and clear the info from the queue as often as it can (ideally once a second as well, but after processing the info, it could take longer). From other thread:

if (query.TryDequeue(out toSomeTuple))
{
    // Process
}

Because this operations will take place under the application's entire life, will this fragment the memory heavily or does the garbage collector takes care of this in any way? Any hints here about how I can optimize this better?

Ulf Honkanen
  • 119
  • 1
  • 8
  • 3
    Worrying about memory fragmentation is a bit like worrying whether the sky is going to fall tomorrow. Hard to avoid noticing that everybody is wearing a blue hat. You have to do it pretty wrong to get that Tuple object promoted out of gen #0. So no, absolutely not. – Hans Passant Sep 22 '16 at 15:22

0 Answers0