I am writing a class the implements a large-ish data store of 2D image data. I currently have code that uses a 3D array, and it works fine but for obvious reasons the OS struggles to allocate memory when the number of images gets large.
For this reason (and other reasons) I am re-writing this data store as a class with a DVR to a queue. Forgetting about the DVR side of it for now, can anybody recommend an efficient way to retrieve a random (i.e. user specified at runtime) element from the queue without actually affecting it.
I have seen various implementations of this, including popping the elements out until the desired one is reached, wiring it out and then pushing the elements back onto the queue. This does not seem like an efficient way of doing things. The only other way I can think of is to use the queue status to return a copy of the elements and then indexing out the desired element. As my queue my be quite large this also does not seem like a nice way of doing things as a double memory allocation is needed? Perhaps for this reason the queue pop-read-push method is better?
For information, I am working with 2D images of 256x256 pixels, at up to 32 bpp (so thats approx 200 kB per image). There could potentially be thousands of images buffered, and I have to do this for several different image sources.
EDIT: the data on my queue is not actually purely a 2D array, it is a class representing an image so it has the 2D data as well as some header information which is a string.
EDIT 2: I am going to benchmark both versions
Edited by neil, 21 June 2012 - 10:22 AM.