Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[Share code] Get available memory
-
Recently, the question came up how to get memory statistics.
I found an Objective-C example on StackOverflow and rewrote it usingctypes
.My gist: https://gist.github.com/lukaskollmer/a09c0278d2d224b9f4839a895ebb9988
Notes:
- There are 2 different total memory counts: "total" and "total (according to Cocoa)"
- Because the graphics card and the CPU share the same memory, the GPU us actually using a part of the RAM for it's graphics memory
- That's why the first total count is smaller. It's only the amount of memory available to the CPU, while the second total count contains both
Example:
-
Very cool this can be expanded to also show the processor count. With only one new line of code.
-
-
Yes it's a balancing act. When do you stop. Is my biggest problem just in Python.
-
Great, thanks a lot. Btw. whats your max. free memory? I got values from 50MB to 300MB. After rebooting my iPad Air 1 e.g. I got 138MB...
-
@brumm I made some tests:
Normal usage
- free memory: 190MB
- used memory: 745MB
After cold reboot
- free memory: 170MB
- used memory: 950MB
After warm reboot
- free memory: 200MB
- used memory: 920MB
-
Okay, now I'm sure that I have too less memory 😞 (even if I get 522MB)
open shp+dbf ('free: ', <__NSCFString: 522,1 MB>)
shp+dbf readed ('free: ', <NSTaggedPointerString: 8,8 MB>)
then crash while writing it in a sqlite dbTrying to convert 80MB of data... with pyshp.
-
Guys, I have two comments. They are not directed at this post, more to share posts generally.
-
I think a nice idea if you share code, you put at least your forum user name in the top of the file. Often I copy share code here , then some weeks later use it. Like to credit the person that shared it. Yes, I can go and copy the name in myself, but I sometimes forget too.
-
Rather than writing results to the console, wouldn't it be better to show them using the dialogs module. It's easy, we can all do it. For a few extra minutes, gives it a lot more professional look.
Look, only suggestions. It's great people share code. Not trying to burden them with extra work. But it's amazing how much things are valued with a little bit of polish.
I haven't followed this way before. But I will try too. Also I will attempt to make it Pass pep8 and pyflakes
-
-
This post is deleted! -
Thanks to all for not causing me further embarrassment on my stupid rant. I have deleted now. Oh well.....
-
This works great to get total memory. Anyone knows how to get memory used by pythonista only? Thanks.
-
https://github.com/jsbain/objc_hacks/blob/master/memstatus.py
the virtual_size field shows the amount of memory used by pythonista .
-
@JonB The Result :
{'system_time': 1.0, 'resident_size': 3041012939227142L, 'policy': 0, 'virtual_size': 551690955866505216L, 'suspend_count': 0, 'user_time': 0.0}- How calc the Pythonista using memory? (just like 320.23MBytes) the virtual_size very large.
- How to get Pythonista CPU loading and Total CPU loading ?
-
Looks like this code does not work properly on 64 bit... i suspect the structure is not sized correctly..