Re: Which is better, pass, or not pass by reference?

From: odel (b_at_twin-pix.com)
Date: 10/21/03


Date: Tue, 21 Oct 2003 14:07:39 +0100

Reference is useful only for object.

if your code is object oriented, then you should always return
references to your objects, never copies, or you will have some
surprises (change the object in one place, without changing it somewhere
else is bad)

for built-in types like strings, integers, booleans , return copies, you
will double the use of memory but for this kind of elements, it has
absolutly NO importance (I'm not even sure you can reference a string
for example).

Now even if your code is not OO, you still have some php functions
returning objects i.e. pg_connect, mysql_result... a connection resource
is an object, a resultset is an object, then if you manipulate them or
return them in some functions, return the reference, not the copy.

another good idea to save your memory is to unset your objects once your
done with 'em, like one would do in C++ maybe.

.b



Relevant Pages

  • [RFC] page replacement requirements
    ... Submitting too much I/O at once can kill latency and even lead to deadlocks when bounce buffers are involved. ... Must be able to deal with multiple memory zones efficiently. ... When on completion of the write to their backing-store the reference bit is still unset a callback is invoked to place them so that they are immediate candidates for reclaim again. ... For traditional page replacement algorithms this is not a big issue since we just implement per zone page replacement; ...
    (Linux-Kernel)
  • Re: Java or C++?
    ... >> CTips wrote: ... GC can only kick in when the last reference has ... If f was already bound to a lot of memory when it enters do-it then ... > more than the extra memory leaked because of sloppy manual deallocation]. ...
    (comp.programming)
  • Re: 4-way Opteron vs. Xeon-IBM X3 architecture
    ... >>>The point here is that the issue concerns both speed AND capacity. ... >As to the reference, the message header points right back in this thread, ... >>>As you may suspect, I read plenty about memory systems, and I would ... >>>from the enthusiast market and assumed that it would work in the server ...
    (comp.sys.ibm.pc.hardware.chips)
  • Re: Garbage Collection Issues in long-standing services
    ... I would agree that I must be holding on to some references, ... store a reference to CS so that it can use it to send data back to the client. ... > By starting another process that allocates memory, ... it does not aggressively cleanup until the amount of physical memory ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A re-announce on GCs defects
    ... It's bad for CPU/Resource intensive but memory cheap objects. ... There may be more than one strong references and you don't know when and where to call Dispose. ... Instead of calling the destructor you call Dispose if the reference counter is 0. ... Note GC in java and C# is not really an addictive as someone would argue since there is no way to do real memory management like delete obj in C++. ...
    (microsoft.public.dotnet.languages.csharp)