473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Best Practices Questions - Sending objects to/from a class modules/functions, etc?

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
Nov 22 '05 #1
0 620

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chuck Ritzke | last post by:
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...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
5
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. ...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
0
by: David Helgason | last post by:
I think those best practices threads are a treat to follow (might even consider archiving some of them in a sort of best-practices faq), so here's one more. In coding an game asset server I want...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
14
by: shamirza | last post by:
Question Do ActiveX DLLs made in VB still need the VB runtimes on the machine? ________________________________________ Answer In a word, Yes. Visual Basic does not support what is known...
2
by: Ing. Davide Piras | last post by:
Hi there, we are rewriting our .NET 1.1 web application with VS. 2005 and .NET 2.0, it takes big work but we believe there is a point to do that... at least we hope! we believe that: 1) the...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.