Solved

Resource Manager vs Resource File C#

Posted on 2011-03-19
4
726 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now