Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 5th, 2004, 4:50 PM   #1
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
I have noticed that PHP has a major appolling lack of support for pointers, being an avid C++'er this can pose a bit of a nuissance, though most need for pointers has been eliminated by PHP's native support for string types, and data serialization and deserialization and dictionary support.

However one problem I have noticed with this is that most web environments limit the amount of memory you are permitted to use to something about 8Mb by default, typically not a problem (more of a problem when you possibly start using Apache 2's multithreaded environment (*shrugs* but I am not 100% sure on that since I have never used it).

Even though 8MB is a lot of data, I am really not a big fan of passing large arrays of values around by value if it is not needed, on one case I have an object which returns an array of data which it stores internally so that other object may access the information, since there is no need for multiple instances of this array (and if there was I could understand copying by value) there is no need to return the array by value either, it is just a waste, and refilling the array I imagine takes processing time.. precious processing time.

So here is a little bit of code I have worked around to allow one to return a value by reference from a function (a little trickier than passing a parameter by reference, though same basic concept is still there)

function &find_var( $param )
{
 ... your code in here...
 return $found_var;
}

$foo =& find_var( $bar );
$foo->x = 2;

One major note of interest I would like to point out is that while the function delaration had changed, the actualy "return $found_var" remained is it would be if you were returning a value (not a reference). Though I understand why, I did not expect this at first since in C++ you would have been required to return the reference with "return &value" (if you object was not already the pointer you needed).

Anyway, just thought I would reflect and share this.
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC