C
Chuck Ritzke
I keep asking myself this question as I write class modules. What's the
best/smartest/most efficient way to send a large object back and forth to a
class module?
For example, say I have a data access module that creates a large
disconnected dataset from a database. I want to pass that dataset back to
the calling program. And then perhaps I want to send that dataset to another
class module.
At first it seems that the "object oriented" approach would be to create a
dataset property in each class module, then run a method that creates the
dataset, and then read the property from the calling program. (and visa
versa if I want to send a dataset to another class module).
Now admittedly, I am not sure I understand how memory is used, garbage
cleanup issues, etc., but this seems inefficient. Won't a separate copy of
the dataset then exist in memory in each of the class modules and the
calling program until the class objects get disposed of?
It seems to me that it would be more efficent to pass a dataset (or any
large object) ByRef to each class as an argument in the method. For example
in the calling program...
Dim MyDataSet as New DataSet
MyObject.MyMethod(MyDataSet)
'Do stuff
MyDataSet=Nothing
and then in the class...
Public Sub MyMethod (ByRef MyDataSet as DataSet)
'Create or use MyDataSet
End Sub
....so that only one copy of the dataset exists at any point in time. Am I
thinking about this correctly?
In a similar vein, it seems convenient sometimes to write Function Subs that
return an object. But then I wonder whether I have cleanup problems because
you can't dispose of the object inside the Function that creates it, if you
need to return the object. I can dispose of the returned object when I'm
done with it, but do I have a problem with a copy of an object remaining
inside the Function Sub? If so, it seems again that I should pass the
dataset as a ByRef argument.
While on the subject of cleaning up. Can someone explain when/if you need to
use the Dispose method for objects that have them? Again with my dataset,
when I am done with it, is there any advantage to...
MyDataSet.Dispose()
MyDataSet=Nothing
I guess I don't understand what Dispose does that Nothing doesn't already
do.
Thanks in advance,
Chuck
Can anybody set me straight here?
Thanks,
Chuck
best/smartest/most efficient way to send a large object back and forth to a
class module?
For example, say I have a data access module that creates a large
disconnected dataset from a database. I want to pass that dataset back to
the calling program. And then perhaps I want to send that dataset to another
class module.
At first it seems that the "object oriented" approach would be to create a
dataset property in each class module, then run a method that creates the
dataset, and then read the property from the calling program. (and visa
versa if I want to send a dataset to another class module).
Now admittedly, I am not sure I understand how memory is used, garbage
cleanup issues, etc., but this seems inefficient. Won't a separate copy of
the dataset then exist in memory in each of the class modules and the
calling program until the class objects get disposed of?
It seems to me that it would be more efficent to pass a dataset (or any
large object) ByRef to each class as an argument in the method. For example
in the calling program...
Dim MyDataSet as New DataSet
MyObject.MyMethod(MyDataSet)
'Do stuff
MyDataSet=Nothing
and then in the class...
Public Sub MyMethod (ByRef MyDataSet as DataSet)
'Create or use MyDataSet
End Sub
....so that only one copy of the dataset exists at any point in time. Am I
thinking about this correctly?
In a similar vein, it seems convenient sometimes to write Function Subs that
return an object. But then I wonder whether I have cleanup problems because
you can't dispose of the object inside the Function that creates it, if you
need to return the object. I can dispose of the returned object when I'm
done with it, but do I have a problem with a copy of an object remaining
inside the Function Sub? If so, it seems again that I should pass the
dataset as a ByRef argument.
While on the subject of cleaning up. Can someone explain when/if you need to
use the Dispose method for objects that have them? Again with my dataset,
when I am done with it, is there any advantage to...
MyDataSet.Dispose()
MyDataSet=Nothing
I guess I don't understand what Dispose does that Nothing doesn't already
do.
Thanks in advance,
Chuck
Can anybody set me straight here?
Thanks,
Chuck