Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

What would be the best way to load images in RAM so I can show them quickly without having a delay when it loads the image. For example, an image changes when the mouse is over it, but there is a delay, because the image still needs to be loaded...
However, making 10 MemoryStreams doesn't look very interesting to me...
Some ideas?

Thanks in advance
MadMatt
Posted

1 solution

It is quite possible but totally depends on how much memory you need for images you want to preload and how likely you need them during certain period of time. Why do you need to keep ten memory streams? You can also keep the the images closer to their, totally loaded, in the image class with all streams closed. It might take even more memory though, certainly if the image is compressed.

I would measure timing and not rush to conclusion. By the way, measuring timing is non-trivial because of JIT. All the code is JIT-compiled on demand on per-method basis. Therefore, calling some methods in the beginning of application run time will take a lot more time than calling them later again, as considerable amount of time will be spend on JIT. Plan your performance measurements thoroughly.

Also, I would recommend to go in for it only of you already have problematic or uncomfortable latency.

—SA
 
Share this answer
 
Comments
_Madmatt 11-Jul-11 11:20am    
Well, actually, I don't measure the time, I can really see the lag... The images aren't quite huge, they're all about 3K PNG files. The methods are called after a while, so I don't think that the JIT is still busy.

Thanks
MadMatt
Sergey Alexandrovich Kryukov 12-Jul-11 10:21am    
This is reasonable. So small files loads very fast; I never saw a lug. Slow computer? Anyway, measure, or experiment with preloading. Do you need them all at the same time (or almost) eventually? If so, you have nothing to loose if you preload them. Only don't keep streams open -- it won't help you because major time is spent not on opening file but to reading it all and decoding data into pixels. Keep preloaded bitmaps.
_Madmatt 13-Jul-11 4:10am    
Thanks! I loaded all the files in Images and set those as source. It works great!
Yes, a slow computer, unfortunately...
Sergey Alexandrovich Kryukov 13-Jul-11 10:47am    
You're welcome.
All right, now, do you see a noticeable improvement over the lag you saw before? I thinks the PNG files are quite small.
--SA
Espen Harlinn 12-Jul-11 10:10am    
Good points - my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900