P
Peter
Hi,
I have a question about good class design ....
In my class I have some properties related to large amount
of data.
What is the best strategy, to include a reference to those
data (and making the object dependent on the client) or
copy the data into the object (independent object) ?
For example ....
class MyClass
{
int [] data; // reference to an int array .. no memory
alloc
(...)
// property Data
public Data
{
get
{
return data;
}
set
{
data = value;
}
}
}
and in the main method:
int [] large_data = new int[1000000];
MyClass myClass = new MyClass();
myClass.Data = large_data;
In this case the member "data" (via Property Data) refers to
"large_data" memory on the heap, like a C pointer.
At the other hand, if the "large_data" memory gets out of
scope, the object will no longer work, because of missing
data.
e.g.
MyClass myClass = new MyClass();
{
int [] large_data = new int[1000000];
myClass.Data = large_data;
}
// here, large_data is out of scope !!
int [] dd;
dd = myClass.Data; // data are missing ???
Some help would be nice.
Thanks,
Peter
I have a question about good class design ....
In my class I have some properties related to large amount
of data.
What is the best strategy, to include a reference to those
data (and making the object dependent on the client) or
copy the data into the object (independent object) ?
For example ....
class MyClass
{
int [] data; // reference to an int array .. no memory
alloc
(...)
// property Data
public Data
{
get
{
return data;
}
set
{
data = value;
}
}
}
and in the main method:
int [] large_data = new int[1000000];
MyClass myClass = new MyClass();
myClass.Data = large_data;
In this case the member "data" (via Property Data) refers to
"large_data" memory on the heap, like a C pointer.
At the other hand, if the "large_data" memory gets out of
scope, the object will no longer work, because of missing
data.
e.g.
MyClass myClass = new MyClass();
{
int [] large_data = new int[1000000];
myClass.Data = large_data;
}
// here, large_data is out of scope !!
int [] dd;
dd = myClass.Data; // data are missing ???
Some help would be nice.
Thanks,
Peter