0

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

3 Answers 3

2
// 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;
Sign up to request clarification or add additional context in comments.

Comments

1

You could look at the following function: http://php.net/manual/en/function.memory-get-usage.php

Comments

-1
function memory_Usage($variable) {
    // how much memory does a variable take up?
    $serializedVar = serialize($variable);
    return strlen($serializedVar);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.