Solved

Resource Manager vs Resource File C#

Posted on 2011-03-19
4
732 Views
Last Modified: 2012-05-11
I have a resource setup with a bunch of 16x16 PNG's that we use for images on a tree view.

We build this treeviews in code and we used to use an imagelist which gaves us trouble so we were adding the images like this:

treeNode.LeftImages.Add(gloabl::project.rsx16.phoneImage);

Now, on a large set of data (7K records, 3 nodes deep so that is 21K nodes) we would randomly get out of memory errors. Even on a dev machine with 8gig ram. So, I did a little digging and found the resourcemanager class in System.Resources, and tried this;

ResourceManager rm = new ResourceManager(resourceFile, etc);
treeNode.LeftImages.Add((Image)rm.GetObject("phoneImage");

I decided before I go further, let me ask, which way is right? Or should I before the loop that  populates the tree create an instance of the image? I want to enusre that ONE instance of the image exists, but also want to follow best practices.

Image phone = (Image)rm.GetObject etc;

treeNode.LefImages.Add(phone);
0
Comment
Question by:melegant99
  • 2
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
MlandaT earned 500 total points
ID: 35386816
I generally find that working with the ImageList is a faster option for working with a large treeview. How about loading the resource images into the ImageList at runtime first? Then just configuring the treeview to use the imageList as normal.

21,000 nodes in a treeview also sounds like overkill... from teh perspective of usability. Does the user really need to have all 21,000 nodes loaded in one go into the tree? How about only adding the child nodes when the user expands a node (might be less responsive than preloading the child nodes, especially where there are many child nodes at the same level, but this results in less runtime memory usage... and even a lower startup time for the tree in the first place since it wont be loading 21,000 nodes)?
0
 

Author Comment

by:melegant99
ID: 35410968
Hi,
If I use an imagelist, does that mean all the nodes will point to one instance of the image in memory, or am I getting an image for every node?

Yes, the 21K is overkill. However it is 21K in a multiple of levels, at the root maybe there are 100 nodes.

Thanks for responding btw, this question sat out there a long time.
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 35414599
ImageList yes. From what I understand, it uses handles and pointers internally so you wont have a copy of the image for each item.

21,000... yes... even if you put it in multiple levels. If you think of it from a usability point of view, it's really a lot for a tree...  I think :) ... I doubt any of your users will ever really need to go through all those items at any one time :)
0
 

Author Closing Comment

by:melegant99
ID: 35414762
Going to change to the tree to be more on demand.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question