Re: Is it worth it to return a resource by reference?



Ney André de Mello Zunino wrote:
Jerry Stuckle wrote:

Passing by reference should never increase the amount of overhead (at least not by any measurable amount), even for an integer. And for more complex objects it will decrease the overhead.


Thanks for your reply. Given that the use of references can never hurt and that this is my first time using them, could you tell me if I am doing it right (according to the sample code in my original post)?

Thank you,


Yep. That's how you return a reference. The only comment which is actually only a matter of style is the generally used syntax is:

function &getPosts(...)

That is, the '&' goes just before the function name instead of immediately after the 'function' keyword. However, it's a matter of style, and either should work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Adding a delimiter inbetween number characters and letter characters
    ... I already knew about those references. ... My post did not violate any rules for this group, ... And you won't believe how many of them thank the regulars here ... However no matter how little one knows about Perl, WHAT one asks, ...
    (comp.lang.perl.misc)
  • Re: Fired
    ... my resignation rather than have to terminate me; in return, ... It's all rhetorical, it's a firing, no matter what kind of pretty ... them your resignation and get good references from them for the ... the job did not sound like the world's best fit ...
    (rec.pets.cats.anecdotes)
  • Re: Yes, Expelled is for the bigots, demonizing atheists
    ... If you haven't been able to find any references to Social Darwinism, ... As a matter of fact, ... safety deserve neither liberty nor safety." ...
    (talk.origins)
  • Re: Its all in the numbers.... (the true nature of evil?) was: Sydney bludgeonings
    ... don't matter. ... Christian, too, Kirk claims to be. ... I provided you with all the sources, with references. ... The first site you "referenced" admits they are a mouthpiece for the ...
    (rec.martial-arts)
  • Re: Newbie: cloning a Number
    ... no references to mutable classes. ... none of them satisfy both and (all of them, as a matter of fact, fail ... I admit that the original formulation ...
    (comp.lang.java.programmer)