PHPã®ã¡ã¢ãªæ¶è²»éã®ç°¡åãªãã³ããã¼ã¯ããã£ã±ããã¡ã
ã¨ãããå³ã
ã½ã¼ã¹ã
ç°å¢ã
LH-MAIN /tmp/test% uname -a Linux LH-MAIN 3.2.8-1-ARCH #1 SMP PREEMPT Mon Feb 27 21:51:46 CET 2012 x86_64 AMD Phenom(tm) II X4 940 Processor AuthenticAMD GNU/Linux LH-MAIN /tmp/test% php --version PHP 5.3.10 with Suhosin-Patch (cli) (built: Feb 6 2012 19:18:12) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies LH-MAIN /tmp/test% cat /etc/php/php.ini | grep memory_limit memory_limit = 2560M
ä½ãããã®ãã¨è¨ãã¨ãPHPã§æ°å¤ãä¿æããã¨æãããé åãæ¶è²»ããã¡ã¢ãªä½¿ç¨éã«ã¤ãã¦æ¸¬å®ãã¦ã¿ãããªããããªäºãããã®ãã¨è¨ãã°ãphp.iniã§ä½ãæãã¨æãããç¨ã«å åãªã¡ã¢ãªã¢ãã±ã¼ãã許容ãã¦ã大ãããµã¤ãºã®é åãæ±ãã¨ä½æ ãã¡ã¢ãªä¸è¶³ã«ãªã£ã¦è½ã¡ãã®ã§ã
çµè«ãè¨èã§è¨ãã¨ãããã®ç°å¢(PHP 5.3.1 @ Arch Linux (x86_64))ã§ã¯ 212.9 [bytes/array-size] ã¨ããæãããäºã«ãªã£ã¦ããäºãå¤ã£ããã¨ãªãã
ããã§ãåä½[array-size]ã¯ãC++çã«èãããªã[sizeof(uint_least32_t)ç¸å½]ã¨èªã¿æ¿ãã¦ãå·®ãæ¯ããªãããªããªãçµæããã¯arrayã®è¦ç´ ã¨ãã¦å ¥ããå¤ã0ã1ã¨è¨ã£ãæ§ãªå°ããªå¤ã§ããã10*pow(2,20)ãããã«è¿ã大ããªå¤ã§ããã¡ã¢ãªä½¿ç¨éã®å¤åã¯å¸¸ã«ä¸å®ã¨è¦åãããããã¡ãªã¿ã«ãarrayã®ä¸ã«æ¾ãè¾¼ãã§ããå¤ã¯ [0 1 2 .. 10 * pow(2,20)] ã¨ããæ°ãC++çã«è¨ãã¨ããã®std::iotaãã¦ããã ãã§ããã®æ大å¤ã¯10,485,760ãå¿è«ã符å·ä»ãã§ãããã«å¯ãã32bitã®æ´æ°åã§æ±ããç¯å²ã§ãããã¨è¨ã訳ã
ã¤ã¾ãããã®ç°å¢ï¼PHPã¯ãã¼ã¸ã§ã³ããããå®è¡ãããOSã«ããæåã®å¤åãæããããã¤ãããã¯ã§ããäºã¯ãå¿ããªãï¼ã§ã¯ãé«ã 32bitã®æ´æ°1ã¤ãPHPãarrayã«æ¾ãè¾¼ãã®ã«ããªãã¨212.9[byte]ãã®ã¡ã¢ãªãå¿ è¦ã¨ãã¦ããã¨èãã¦å·®ãæ¯ããªããè¨ãã¾ã§ãç¡ãã32bitã®æ´æ°ãæ±ãã®ã«å¿ è¦ãªæ å ±éã¯å½ç¶é«ã 32[bits]ã4[bytes]ã§ããã»ï½ã»ï¼
ã¡ãã£ã¨æå³ã解ããªãã
PHPã¨ã¯ä¸ä½ä½ãªã®ãâ¦ã
ã¡ãªã¿ã«ãç°å¢å¤ããã°ã¨è¨ã訳ã§ãã®ã®ã¤ãã§ideoneããã«ãæãã¦ã¿ãã
- Ideone.com | M5AQV
arrayãæ¡å¼µããäº102,400åãã¨ã«å¡ã7.08[MiB]å¢å ãã¦ãããã¤ã¾ãã 72.52 [bytes/array-size] ã¨ããäºã«ãªãâ¦ã
ãã£ãã®ç°å¢ã«æ¯ã¹ãã¨34%ç¨ã®ã¡ã¢ãªæ¶è²»éã¨éåã³ã³ãã¯ããªæ§ã ã
â¦ä½ããç¹°ãè¿ãã32bitã®æ´æ°å¤ãä¿æããã®ã«å¿ è¦ãªæ å ±éããèªä½ã¯é«ã 32[bits]=4[bytes]ã§ããããC++ãCã§ããã°ã©ã ãæ¸ãã¦ãuint_least32_tãnewãªãmallocãã¦ããå®éã«ã¯ã¡ã¿ãã¼ã¿ãå¿ è¦ãããªãï¼ãã¨ãã主張ããããæ¹ãããã°ãããããããã ãããã¨çããããstd::unique_ptrããstd::vectorãã使ã£ããã©ãã®ã¨è¨ãããã°ããã¾ããããã ãããã¨çããããããã§ãã¡ã¢ãªæ¶è²»éããã¼ã¿æ¬ä½ã®53åã«è¨ãä¸ãã£ããã18åã«è¨ãä¸ãã£ããã¯ããªãã»ï½ã»ï¼
ããã§ãµã¨æãåºããã®ã ãã©ãä¸ã®ä¸ã«ã¯æ±ã£ã¦ããå¤ãä½ã§ãããå é¨çã«ã¯å ¨ã¦ãæååã¨ãã¦æ±ãã¨ããã¼ãã®ãåå¨ãã¦ããäºãæã©ããã§èãããè¦ããããæ§ãªè¨æ¶ãç¡ãäºãç¡ãã
æåã®ç°å¢ã¨æ¬¡ã®ç°å¢ã§ã¯PHPã®å®è¡ç°å¢ã®ã¢ã¼ããã¯ãã£ãx86_64(64-Bit)ã¨i686(32-Bit)ã¨å¤§ããªéãï¼ãã®ç°å¢ã«ããéãã¯53åã¨ã18åã§ã¯ãªãã¦3åç¨åº¦ã§ãããªããã»ã»ã»3åã»ã»ã»ï¼ãããããããã«ãããã®ç°å¢ã®PHPããã«ãããGCCã®ãã¼ã¸ã§ã³ããªãã·ã§ã³ãã大ããéãå¯è½æ§ãé«ãããã§ã»ã»ã»ããããã¸ãã¨å é¨çã«å®éã«ã¯æååã¨ãã¦ã¡ã¢ãªã¢ãã±ã¼ãããã¦ããã£ã¦äºãçµã¿åãããã¨ããããæãããäºã«ç¹ããã®ããªãã»ã»ã»ã
ãã¦ãããPHPã®äºãªãã¦æ¸ããããªãã®ã§ããã®ã®ã¤ãã§ã«ä»æ¥ãã£ãPHPã®ã¢ã¬ã²ãªãã¿ã2ã¤ãã¾ãã§ãã¿ãâã
ãã®ãã¡âã
ããããã£ã±ãPHPã¯ãã¡ã ãåè¨æ¤åã楽ãããªãï¼¾ï¼¾ï¼ array_map jp2.php.net/manual/ja/func⦠array_walk jp2.php.net/manual/ja/func⦠ãã©ã¡ã¼ã¿ã¼ã®é åºã§ã¹ãã¬ã¹ãããããPHPãããããããã§ããã»ï½ã»ï¼
— ä¼è¤ å
(å®éã«ããã)ãã (@USAGI_WRP) 3æ 3, 2012
ãã®ã«âã
ã¨ããããã¨ãªã®ã§ã»ãã»ãâ¦ã¨ã ideone.com/Oqk5a ã¨ãæ¸ãã¦ãï¼PHPããï¼ï¼ jp2.php.net/manual/ja/func⦠ãï¼ jp2.php.net/manual/ja/lang⦠ãï¼ã£ã¦ãªã£ãã®ã§ããPHPã¯å¿ããæ¹ã幸ãã«é·çãã§ããã¨æãã¾ãããã¾ãã
— ä¼è¤ å
(å®éã«ããã)ãã (@USAGI_WRP) 3æ 3, 2012
ããããã£ã±ãPHPã¯ãã¡ã ã»ï½ã»ï¼
å°ãªãã¨ãä¸åã¯ççºãã¦å¤§ç ´å£ãããæ¹ãããã¨æãã