Windows Form Application vb net
I have many container files on a hard drive, inside of them are many images. I have to get a particular image by using an ID to do this I have to go trough each of the container files and find the one which has the ID in it then I can retrieve the image.
I think I have 3 options:
- load all the images at start up into memory, some images may or may not be used.
- as I need each image go through all the container files and open the image into memory.
- create a dictionary of IDs and what file they are in at start up and then get each image as I need it without have to go thro开发者_开发百科ugh all the container files.
Which option is better in that there is less delay between the user asking for the image and the image being shown, but doesn't use too much memory or slow downthe computer
(average computer memory of the users who would use thisapplication is about (2-)3-4GB
Does the location of the images in relation to the container file change over time? If not, one option would be to have a one-time operation that will index the files and write this information into a separate file. This index file could be loaded at startup, and then your code would know in which contaier to find a particular image.
The amount of memory on user computer is not that important - this memory is not yours and it's the user that decides how to deal with that memory. Your task is to find proper balance between memory consumed (try to keep it minimal) and speed of operations.
The choice will depend on the number of containers and the number of images in each container.
If the number is small, load everything to memory and don't bother.
Dictionary of IDs is the preferred "generic" way, when the number of containers and files is unknown.
There's one more thing to think about -- how are IDs generated AND stored? For example, if containers are named AA to ZZ and image IDs are numeric, then you could store references as "BS123", which, when you need an image, will tell you to open container BS and take image 123.
精彩评论