Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Collection is removed from memory after a while
Message
From
15/11/2013 14:19:58
 
 
To
15/11/2013 14:16:54
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01588067
Message ID:
01588083
Views:
24
>>>Well, look at what I have found:
>>>
>>>http://msdn.microsoft.com/en-us/library/ff647802.aspx
>>>
>>>...especially in the Boxing section:
>>>
>>>"Excessive boxing often occurs where you use collections that store System.Object types. Consider using an array or a custom-typed collection class instead."
>>>
>>>So, the usage of an array seems to be recommanded. This is like the issue with the StringBuilder that I had to change recently with a string to avoid a heap.
>>>
>>>Anyone can provide feedback on this and if this makes sense?
>>
>>
>>Why don't you use a Dictionary< string, Tuple< int, int >> to store the image data ?
>>
>>You don't need to loop through the collection to find the image. You can retrieve the data with a simple TryGetValue()
>>
>>
>>	class ImageData
>>	{
>>		internal int Width  { get; private set;}
>>		internal int Height { get; private set; }
>>
>>		internal ImageData( int width, int height)
>>		{
>>		
>>			Width = width;
>>			Height = height;
>>		}
>>	}
>>
>>	static  class TestImage
>>	{
>>
>>		internal static void Go()
>>		{
>>			Dictionary<string, ImageData> images = new Dictionary<string,ImageData>();
>>
>>			images.Add("image1", new ImageData(10, 20));
>>			images.Add("image2", new ImageData(30, 40));
>>
>>			string s = "image4";
>>
>>			bool found = false;
>>			ImageData imagedata;
>>
>>
>>			if( images.TryGetValue(s, out imagedata) )
>>				found = true;
>>		
>>			
>>		}
>>	}
>>
>
>We've recommended use of a Dictionary over the VB specific collection before (see thread 1574508). Also, if he just needs to know if the data exists and not the actual value, ContainsKey will work as well.



I know that - but the first message retrieves the Width and the Height - hence the use of TryGetValue() - two birds with one stone
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform