How can I add an item to a list if that item is essentially a pointer and avoid changing every item in my list to the newest instance of that item?
Here's what I mean:
I am doing image processing, and there is a chance that I will need to deal with images that come in faster than I can process (for a short period of time). After this "burst" of images I will rely on the fact that I can process faster than the average image rate, and will "catch-up" eventually.
So, what I want to do is put my images into a <List>
when I acquire them, then if my processing thread isn't busy, I can take an image from that list and hand it over.
My issue is that I am worried that since I am adding the image "Image1" to the list, then filling "Image1" with a new image (during the next image acquisition) I will be replacing the image stored in the list with the new image as well (as the image variable is actually just a pointer).
So, my code looks a little like this:
while (!exitcondition)
{
if(ImageAvailabe())
{
Image1 = AcquireImage();
ImgList.Add(Image1);
}
if(ImgList.Count > 0)
{
ProcessEngine.NewImage(ImgList[0]);
ImgList.RemoveAt(0);
}
}
Given the above, how can I ensure that:
- I don't replace all items in the list every time Image1 is modified.
- I don't need to pre-declare a number of images in order to do this kind of processing.
- I don't create a memory devouring monster.
Any advice is greatly appreciated.