Memory Consumption | SoloLearn: Learn to code for FREE!

0

Memory Consumption

Determine the total memory consumption by following the sequence. List1 = [40,45, "Ekta"] i. excluding memory consumption by actual data ii. including memory consumption by actual data Please explain me its solution List1 = [40,40.5, "Ekta"] i. list overheads = 26 Reference pointer size = 4 bytes (on 32 bit implementation) Length of the list =3. Memory consumption for list = 3 List overheads + Reference points size x length of the list. = 36 + 4 3 = 48 bytes. ii. Memory consumption by data. There are 3 values 1. integer i.e. 40 memory consumption = 12 bytes 2. float i.e. 40.5 memory consumption = 16 bytes 3. string i.e. "Ekta" iii. memory consumption = overloads + 1 * string length = 21 bytes + 1 * 4 = 21 + 4 = 25 bytes memory consumption by data = 12 + 16 + 25 = 53 bytes memory consumption for list l including actual data = 48 + 53 = 101 bytes

3 Answers

New Answer

+2

Aaron Eberhardt Still I didn't get your point, please elaborate

+1

♤♢☞ 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 ☜♢♤ calculating the exact memory consumption in Python is mostly useless. First of all this depends on the implementation of the Python interpreter and therefore the calculated value isn't very meaningful. Then there's the problem that Python doesn't have deterministic memory usage because it has a runtime and a garbage collector. So even if we had the correctly calculated value for the memory consumption of our data it wouldn't necessarily represent the additional memory consumption of the Python runtime. The whole point of Python is simplicity not efficiency and if you're start counting bytes in Python you're probably using the wrong language. I'm not saying the question isn't interesting, it's good to know that Python in this case has a massive overhead over systems programming languages but the exact memory consumption has no meaning in the real world.

-1

This seems like a breakdown of memory consumption of a specific Python implementation. It's interesting to see that there is a significant overhead using Python over more low level languages but the details wouldn't worry me if I'd use Python. If I someone cares about memory consumption he wouldn't use Python anyway but a systems programming language like C/C++ or Rust where memory usage is much more deterministic and predictable.