Functions pass by ref or by value?

Discussion in 'ASP General' started by Joe, Aug 27, 2005.

  1. Joe

    Joe Guest

    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.
     
    Joe, Aug 27, 2005
    #1
    1. Advertising

  2. "Joe" <> wrote in message
    news:...
    >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.
     
    Egbert Nierop \(MVP for IIS\), Aug 27, 2005
    #2
    1. Advertising

  3. Joe wrote:
    > 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

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Aug 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Radde
    Replies:
    38
    Views:
    1,014
  2. Replies:
    0
    Views:
    349
  3. Replies:
    22
    Views:
    775
    peter koch
    Apr 30, 2008
  4. Replies:
    6
    Views:
    359
    James Kanze
    Apr 29, 2008
  5. Navindra Umanee

    strong ref from weak ref?

    Navindra Umanee, Feb 12, 2005, in forum: Ruby
    Replies:
    2
    Views:
    147
    Navindra Umanee
    Feb 12, 2005
Loading...

Share This Page