Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9698

Re: Exhaustive memory allocation using arrays

From Christoph Becker <cmbecker69@gmx.de>
Newsgroups comp.lang.php
Subject Re: Exhaustive memory allocation using arrays
Date 2013-05-29 13:00 +0200
Organization Aioe.org NNTP Server
Message-ID <ko4n4o$4ec$1@speranza.aioe.org> (permalink)
References <c85ab849-eed2-4dce-8d22-074867a93ab5@googlegroups.com> <3a174203-4ba5-4cd2-acc7-6efd74af13b7@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Exhaustive memory allocation using arrays tombert.at@gmail.com - 2013-05-28 23:27 -0700
  Re: Exhaustive memory allocation using arrays tombert.at@gmail.com - 2013-05-28 23:42 -0700
  Re: Exhaustive memory allocation using arrays tombert.at@gmail.com - 2013-05-29 00:45 -0700
    Re: Exhaustive memory allocation using arrays Christoph Becker <cmbecker69@gmx.de> - 2013-05-29 13:00 +0200
  Re: Exhaustive memory allocation using arrays Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-29 08:22 +0000
    Re: Exhaustive memory allocation using arrays The Natural Philosopher <tnp@invalid.invalid> - 2013-05-29 09:54 +0100
  Re: Exhaustive memory allocation using arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-29 15:30 +0200

csiph-web