ConcurrentQueue<T> and Contiguous Memory

O

O.B.

Does anyone know if the
System.Collections.Concurrent.ConcurrentQueue<T> uses a
System.Collections.Generic.Queue<T> under the hood? The reason I ask
is that I need a thread-safe queue that uses non-contiguous memory.
In the past, I have avoided using Queue<T> because it required
contiguous memory for its internal array of data.

It looks like ConcurrentQueue<T> could save me some lines of code, but
the performance may be drastically impacted if it uses arrays that
require contiguous memory.

-Obie
 
O

O.B.

You can look yourself, either using Reflector or looking at the public
.NET source code which Microsoft provides.

I'm curious what the requirement for non-contiguous memory is.  Are you
trying to avoid some particular caching problem?  Something else?  I
would say that in general, if you care about the memory organization,
managed code is probably an inappropriate solution altogether.

Alternatively, even if a queue manages data contiguously, if you really
need individual elements to be non-contiguous, you could achieve the
same results as effectively as using other techniques, without any
additional inefficiency, simply by inserting dummy elements in the queue
data.

Which is to say that, in managed code other techniques may not result in
the memory being used being all that non-contiguous either, even if
you're doing your best to keep the usage non-contiguous.  :)

All that said, if you already have a data structure implementation that
addresses the non-contiguous aspect of your requirement, making it
thread-safe should not be all that hard.  It might make more sense to
approach the problem from that direction.
g
Pete

After the program runs for about a week, the memory gets very
fragmented. We have encountered problems in the past with out of
memory exceptions when using an List<T>. When we switched to a
LinkedList<T>, the problem went away.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top