FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Exhaustive memory allocation using arrays
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Exhaustive memory allocation using arrays [message #181750 is a reply to message #181746] Wed, 29 May 2013 11:00 Go to previous messageGo to previous message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma:
Member
tombert.at wrote:
> And, doubling the memory size by assigning a new value:
>
> for ($i=0; $i < 1000000; $i++) {
> $value[$i] = "23.4567890123";
> }
> for ($i=0; $i < 1000000; $i++) {
> $value[$i] = sprintf("%f", $value[$i]);
> }
>
> Now php is using ~400 MB

I *assume* that the strings in the first loop do not actually allocate a
struct str for every instance, but instead reference a single statically
allocated instance. The second loop is probably allocating a new struct
str for every sprintf().

Compare with:

for ($i=0; $i < 1000000; $i++) {
$value[$i] = "23.4567890123";
}
for ($i=0; $i < 1000000; $i++) {
$value[$i] = floatval($value[$i]);
}

--
Christoph M. Becker
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Parsing mbox files with Windows Php
Next Topic: UML
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 05:22:04 GMT 2024

Total time taken to generate the page: 0.06987 seconds