3

PHP数组占多大内存

 1 year ago
source link: http://abcdxyzk.github.io/blog/2022/09/24/lang-php-mem/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PHP数组占多大内存

2022-09-24 20:20:00

http://t.zoukankan.com/sailrancho-p-3892291.html

简单的写一个代码

<?php
$m1 = memory_get_usage();

$arr = array(
);

$m2 = memory_get_usage();

$arr2 = array(
    'testa'=>'hello world1',
    'testb'=>'hello world2',
);

$m3 = memory_get_usage();

echo $m1.PHP_EOL;
echo $m2.PHP_EOL;
echo 'usage: '.($m2-$m1), PHP_EOL;
echo $m3.PHP_EOL;
echo 'usage: '.($m3-$m2), PHP_EOL;
92216
92656
usage: 440
93432
usage: 776

memory_usage的单位是B(Byte), 也就是一个空数组是440B, 有内容以后是776B, 还是很占内存的。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK