[nycphp-talk] Accessing non-existent array elements ok?
tedd
tedd at sperling.com
Tue Aug 19 10:45:43 EDT 2008
At 9:18 AM -0400 8/19/08, David Mintz wrote:
>On Mon, Aug 18, 2008 at 11:27 PM, Daniel Convissor
><<mailto:danielc at analysisandsolutions.com>danielc at analysisandsolutions.com>
>wrote:
>
> > >Does using an array reference &$array buy you anything in this instance?
>>
>> The basic idea is you don't know how big the array is and you don't want
>> to pass anything more than you want to.
>
>PHP functions always act on a pointer/reference of the input value UNTIL
>you write to it. So, in this case, making $array a reference buys you
>nothing. I don't know if it penalizes you, though.
>
>I heard somewhere that it does cost to reference/de-reference for no
>good reason, and that if youi're not going to write to it, pass it
>by value not reference. But I don't remember when or where, so don't
>ask me support that with things like facts or sources.
>
>--
>David Mintz
David:
A reference is an allocation of memory and a dereference is dropping
a segment of memory. That takes cpu time and memory to do so -- so it
should be for a good reason.
Also, depending upon the type of memory manager used, referencing and
dereferencing memory can fragment available memory and eventually
cause a program to crash when the amount of memory required to
continue is not available.
Back in my old working with Macintosh days, we seldom asked for a
pointer, but rather a handle (a pointer to a pointer) and that
allowed the Macintosh Memory Manager to organize/optimize available
memory, thus Macs had less crashes than the windoze world.
Now, how php handles memory I am totally clueless -- anyone care to
enlighten me?
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
More information about the talk
mailing list