
Hello, On Tue, 31 Mar 2020 07:40:01 +1100 Chris Angelico <rosuav@gmail.com> wrote:
On Tue, Mar 31, 2020 at 7:04 AM Paul Sokolovsky <pmiscml@gmail.com> wrote:
for i in range(50000): v = u"==%d==" % i # All individual strings will be kept in the list and # can't be GCed before teh final join. sz += sys.getsizeof(v) sb.append(v) s = "".join(sb) sz += sys.getsizeof(sb) sz += sys.getsizeof(s) print(sz)
... about order of magnitude more memory ...
I suspect you may be multiply-counting some of your usage here. Rather than this, it would be more reliable to use the resident set size (on platforms where you can query that).
I may humbly suggest a different process too: get any hardware board with MicroPython and see how much data you can collect in a StringIO and in a list of strings. Well, you actually don't need a dedicated hardware, just get a Linux or Windows version and run it with a specific heap size using a -X heapsize= switch, e.g. -X heapsize=100K. Please don't stop there, we talk multiple implementations, try it on CPython too. There must be a similar option there (because how otherwise you can perform any memory-related testing!), I just forgot which. The results should be very apparent, and only forgotten option may obfuscate it. [] -- Best regards, Paul mailto:pmiscml@gmail.com