Functions pass by ref or by value?

J

Joe

I have a function called GetRS which takes in a SQL string and returns a
recordset object. Does this mean that a copy of the recordset is returned or
is it passed by reference?

Obviously this could have a large impact on performance for large
recordsets.
 
E

Egbert Nierop \(MVP for IIS\)

Joe said:
I have a function called GetRS which takes in a SQL string and returns a
recordset object. Does this mean that a copy of the recordset is returned
or is it passed by reference?

Obviously this could have a large impact on performance for large
recordsets.

Hi,

If you pass an object 'byval' it is passed as (for instance _Recordset*
pRs), while 'byref' in C++ code, would be _Recordset** pRs.

In the first, case, a pointer to the instance of the object is sent, in the
second case, a pointer to the pointer of the instance. As you understand,
you don't create a in memory-copy.

When we speak about VARIANTS, which is default for ASP and vbscript, the
same happens (more or less) with instances of objects.
But when a variant, contains a string or a date, when passed 'byval', a
fresh copy is made which is obviously slower. In our current time :),
speaking about a normal server, a PIV 3GH this is peanuts. The real benefit
is when your SQL code or other network related functions halt thread
execution.
 
B

Bob Barrows [MVP]

Joe said:
I have a function called GetRS which takes in a SQL string and
returns a recordset object. Does this mean that a copy of the
recordset is returned or is it passed by reference?

Obviously this could have a large impact on performance for large
recordsets..

Objects are always passed by reference (given that they are not crossing
process bondaries)

http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx
http://blogs.msdn.com/ericlippert/archive/0001/01/01/53005.aspx

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top