Do not tell the function to calculate the weight of the variable (array)
- five3-4 kg will be. - Oleg
- Will request the same =)) - Vitaly Kustov
- @exec that's just why the phrase how much a movie weighs or photo doesn't bother anyone ...;) - FLK
- 2I would understand the question as well as @FLK, find out how much variable RAM is eating. Plus - Vitaly Kustov
- Yes? And what is this nonsense then work? Why measure the array in RAM? - AseN
3 answers
$before=0; $a='ΠΈΡΠΏΡΡΡΠ΅ΠΌΠ°Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½Π°Ρ Π»ΠΈΠ±ΠΎ ΠΌΠ°ΡΡΠΈΠ²'; $before = memory_get_usage(); unset($a); echo 'ΡΠ°Π·ΠΌΠ΅Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΡΠΎΡΡΠ°Π²ΠΈΠ»: ',$before-memory_get_usage(),' Π±Π°ΠΉΡ';
upd @ Sh4dow is in fact, 208 bytes in $ before, and echo is free (as I understand it, because the line is not loaded into memory, but immediately output) and there are a few more nuances, from critical that php automatically optimizes memory consumption and if the variables have the same value, then the memory is allocated for the latter only to create the link (208 bytes), so the construction is:
$a='ΠΈΡΠΏΡΡΡΠ΅ΠΌΠ°Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½Π°Ρ Π»ΠΈΠ±ΠΎ ΠΌΠ°ΡΡΠΈΠ²'; $a=$b; $before = memory_get_usage(); unset($a); echo 'ΡΠ°Π·ΠΌΠ΅Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΡΠΎΡΡΠ°Π²ΠΈΠ»: ',$before-memory_get_usage(),' Π±Π°ΠΉΡ';
returns 208 bytes for a number, 128 for a string or array.
ps and that's why so much memory is allocated for the number, a mystery to me.
- If I'm not mistaken, is this a very approximate size? Type -4 bytes to
$before
and lines to echo. In general, it seems to me, the only option for php is to dump a variable into a file and watch its size) And there you can write and even pervert through the pack through the pack ... - Sh4dow - one> Actually, it seems to me that the only option for php is to dump a variable into a file and watch its size) It won't work either. The size of the dump and how much the variable takes with all the internal structures in PHP are weakly correlated. Something like this: $ before = memory_get_usage (); $ a = 'test variable or array'; echo memory_get_usage () - $ before; But this is also not always applicable. - Ilya Pirogov
- @Ilya Pirogov either define $ before before use. and as I have already updated the answer, simply assigning a result to another variable will not give, only the creation of a unique value. - FLK
- @Ilya Pirogov meant "data volume". Those. in the file, you can represent an array of numbers as a hex-string, numbers as strings, etc. and only in this case we will have exactly the amount of data up to a byte, without looking at the coding links and other phr-crutches. - Sh4dow
- 2About the size of allocations - [ habrahabr.ru/post/141093 ] [1] [1]: habrahabr.ru/post/141093 - Costantino Rupert
If I correctly understood the question then:
sizeof - ΠΏΠΎΠ»ΡΡΠ°Π΅Ρ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² Π² ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠΉ.
Weight - ahahah =) Prikolno said: "Variable weight")))
Function:
count(array)
also return the length of the array)
PS At this rate, there will soon be questions like: "How to look into the anus of Windows" =)))
- 2or maybe it means that to find out how much this variable in memory takes place? - Smash