简体   繁体   English

PHP-数组的每个元素允许的最大大小

[英]PHP - Maximum size allowed for each element of array

In my program I have 12 multidimensional arrays which their size vary between 200-7000. 在我的程序中,我有12个多维数组,它们的大小在200-7000之间变化。 Each cell in array contains a float number with high precision (eg 0.0000000000000123344) and these arrays pass values to each other for some calculations. 数组中的每个单元格都包含一个具有高精度的浮点数(例如0.0000000000000123344),并且这些数组将值彼此传递以进行一些计算。 some times I get the error of lack of memory in some arrays (I have changed all configurations related to memory and it is set to maximum ). 有时,我会收到一些数组缺少内存的错误(我更改了与内存相关的所有配置,并将其设置为maximum)。 I'm wondering what is the maximum size allowed to store a float in a huge array? 我想知道允许在大型数组中存储浮点数的最大大小是多少? Thank you. 谢谢。

Finally I could find the solution. 终于我找到了解决方案。 I found that when the PHP collection garbage is getting full, there is no way to free it. 我发现,当PHP收集垃圾变满时,无法释放它。 Unset and gc_collect_cycles() also are not effective. Unsetgc_collect_cycles()也无效。 The only way is to use **Function** over different section of codes. 唯一的方法是在代码的不同部分使用**Function** In my case, I had a big script in a for loop , so I copied all my codes in a function, and in my loop I call the function. 就我而言,我在for loop有一个大脚本,因此我将所有代码复制到一个函数中,然后在循环中调用该函数。 Each time function quiets, memory gets free. 每次函数安静时,内存就会释放。 You may test it by adding memory_get_usage() once in your function and once out of the function to see the difference. 您可以通过在函数中添加一次memory_get_usage()并在函数之外添加一次memory_get_usage()来进行测试,以查看两者之间的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM