Memory usage.

N

Nick

I have a program that generates a custom bimap every 50ms. Which is slow, but no way to make it faster.
Now I want to keep it generating as fast as possible (which is 50 ms).
But I have to store these images somewhere.
The only place I can think of is ram.
What effect would so many bitmaps have on memory usage (maybe tens of thousands).
Im imagining it memory usage would be unaccaptable. Am I wrong?
How big is one bitmap object in memory?
Would it make a difference if I use an Image object?

Any help is greatly appreciated.
Thank you.
Nick Z.
 
J

Jon Skeet [C# MVP]

Nick said:
I have a program that generates a custom bimap every 50ms. Which is
slow, but no way to make it faster.
Now I want to keep it generating as fast as possible (which is 50
ms).
But I have to store these images somewhere.
The only place I can think of is ram.

Why not store them on disk? If you have one thread creating bitmaps and
one thread writing them to disk, with a queue between them, I wouldn't
have thought you'd have too many problems.
 
N

Nick

Jon said:
Why not store them on disk? If you have one thread creating bitmaps and
one thread writing them to disk, with a queue between them, I wouldn't
have thought you'd have too many problems.

Well I thought it would take too long.
Could you please explain what you mean by using two threads and a queue between them?
Two programs running? Or do you mean hyper threading? Im no pro as you can tell.

Thank you.
Nick Z.
 
J

Jon Skeet [C# MVP]

Nick said:
Well I thought it would take too long.
Could you please explain what you mean by using two threads and a
queue between them?
Two programs running? Or do you mean hyper threading? Im no pro as
you can tell.

I mean just two threads in the same process. See
http://www.pobox.com/~skeet/csharp/multithreading.html

You'd want to use two threads so that one would be doing the IO while
the other was generating the images themselves. You might want to limit
the size of the queue so that if the generation thread got too far
ahead, you could just wait for the IO thread to catch up a bit rather
than keeping on generating and potentially running out of memory.
 
N

Niki Estner

Nick said:
I have a program that generates a custom bimap every 50ms. Which is slow, but no way to make it faster.
Now I want to keep it generating as fast as possible (which is 50 ms).
But I have to store these images somewhere.


How big are these bitmaps, and how many are there going to be? If they can
be created in 50 ms, why do you have to store them at all, and not create
them on demand?
The only place I can think of is ram.

The harddrive is another place; But that depends on your images' sizes;
Writing big consecutive blocks on a defragmented medium is pretty fast.
What effect would so many bitmaps have on memory usage (maybe tens of
thousands).

Not sure if I got that question right... Of course they will *consume*
memory. And it's limited. But I think you already knew that.
Im imagining it memory usage would be unaccaptable. Am I wrong?
How big is one bitmap object in memory?

This all depends on the size of your images.
If you had to store 640x480x24 images, one uncompressed image would take
roughly 1MB (640 * 480 * 3), so you won't be able to store more than a few
hundred of them in memory.

I think if the images are about 320x240 or smaller you can effectively
compress them to an MPEG stream and save that to disc (Lossy compression).
Would it make a difference if I use an Image object?

System.Drawing.Image is abstract; You can't create objects of it.

Niki
 

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