php multidimensional arrays, memory management
i need a structure like this
array(){
[0] => array(){
[0] => array(){
// this array will have 'n' values(n is large, like 2000)
}
[1] => array(){
// this array will have 'n' values(n is large, like 2000)
}
}
.
.
.
[n] => ............
}
n arrays will each have a 2 element array, where each element has an array of n values.
I used $list[$m][0][$n]
and 开发者_运维百科$list[$m][1][$n]
inside 2 for loops where $m,$n
vary from 0...2000
this crosses the allowed memory size.. i can change the size in php.ini, but i want to optimize my memory usage and not change the limit.
will using objects help ?
Please provide some sample code to understand. Thank you.
Using objects will most likely not help (it might even be worse).
What you need to do, in a case such as this one, is re-think :
- either your design : there must be another way to achieve what you want
- possibly, using another algorithm ?
- or storing some "temporary data" elsewhere than in memory ? In an SQLite database, for instance ?
- or the language you'll use for your script
- PHP is not always the best tool for the job.
Assuming that the net weight of your data crosses the memory limit, I can't see how objects could be of help. For the purposes of data storage, they're just a different form of notation, really. Maybe one method will save a byte per piece over the other - I don't know, but if there's a difference, my bet is objects are more expensive.
But I think the general question is what you are trying to do with that lot of data? Could it be feasible to store parts of it to disk or the database, and have only a part of it in memory?
精彩评论