R
Rune B
Hi Group
I was considering using a Generic Dictionary<> as a value container inside
my business objects, for the reason of keeping track of fields changed or
added and so on.
- But how expensive is it to instantiate/use Generic Dictionaries in great
numbers (let's just say 100000's ), in terms of memoryuse and performance?
Any practical experiences out there?
--------------
Simplified example:
public class SomeItem
{
public SomeItem()
{
}
private Dictionary<string, object> _values = new Dictionary<string,
object>();
private string GetString(string fieldname)
{
if(_values.ContainsKey(fieldname))
return _values[fieldname];
return null;
}
private void SetValue(string fieldname, object value)
{
if(_values.ContainsKey(fieldname))
_values[fieldname] = value;
else
_values.Add(fieldname, value);
}
public string Key
{
get { return this.GetString("Key"); }
set { this.SetValue("Key", value); }
}
public string ItemName
{
get { return this.GetString("ItemName"); }
set { this.SetValue("ItemName", value); }
}
// and a number of properties more
}
I was considering using a Generic Dictionary<> as a value container inside
my business objects, for the reason of keeping track of fields changed or
added and so on.
- But how expensive is it to instantiate/use Generic Dictionaries in great
numbers (let's just say 100000's ), in terms of memoryuse and performance?
Any practical experiences out there?
--------------
Simplified example:
public class SomeItem
{
public SomeItem()
{
}
private Dictionary<string, object> _values = new Dictionary<string,
object>();
private string GetString(string fieldname)
{
if(_values.ContainsKey(fieldname))
return _values[fieldname];
return null;
}
private void SetValue(string fieldname, object value)
{
if(_values.ContainsKey(fieldname))
_values[fieldname] = value;
else
_values.Add(fieldname, value);
}
public string Key
{
get { return this.GetString("Key"); }
set { this.SetValue("Key", value); }
}
public string ItemName
{
get { return this.GetString("ItemName"); }
set { this.SetValue("ItemName", value); }
}
// and a number of properties more
}