Reputation: 13184
Is there any simple way to check how much memory does some array take?
Like I've got some 10k rows array and need to know how much MB/KB it takes for server to remember it inside some $arr
Upvotes: 0
Views: 144
Reputation: 7
function memory_Usage($variable) {
// how much memory does a variable take up?
$serializedVar = serialize($variable);
return strlen($serializedVar);
}
Upvotes: -1
Reputation: 212402
// how much memory are you using before building your array
$baseMemory = memory_get_usage(false);
// create your array
$a = array('A',1,'B',2);
// how much memory are you using now the array is built
$finalMemory = memory_get_usage(false);
// the difference is a pretty close approximation
$arrayMemory = $finalMemory - $baseMemory;
Upvotes: 2
Reputation: 9040
You could look at the following function: http://php.net/manual/en/function.memory-get-usage.php
Upvotes: 1