omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    ctypes
    7
    14
    10609
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lukaskollmer
      lukaskollmer last edited by

      Recently, the question came up how to get memory statistics.
      I found an Objective-C example on StackOverflow and rewrote it using ctypes.

      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:

      1 Reply Last reply Reply Quote 4
      • chibill
        chibill last edited by

        Very cool this can be expanded to also show the processor count. With only one new line of code.

        1 Reply Last reply Reply Quote 0
        • lukaskollmer
          lukaskollmer last edited by

          @chibill I know. You can use

          NSProcessInfo.processInfo().activeProcessorCount()
          

          1 Reply Last reply Reply Quote 1
          • Phuket2
            Phuket2 last edited by

            Yes it's a balancing act. When do you stop. Is my biggest problem just in Python.

            1 Reply Last reply Reply Quote 0
            • brumm
              brumm last edited by

              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...

              1 Reply Last reply Reply Quote 0
              • lukaskollmer
                lukaskollmer last edited by

                @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
                1 Reply Last reply Reply Quote 1
                • brumm
                  brumm last edited by brumm

                  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 db

                  Trying to convert 80MB of data... with pyshp.

                  1 Reply Last reply Reply Quote 0
                  • Phuket2
                    Phuket2 last edited by

                    Guys, I have two comments. They are not directed at this post, more to share posts generally.

                    1. 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.

                    2. 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

                    1 Reply Last reply Reply Quote 1
                    • Phuket2
                      Phuket2 last edited by

                      This post is deleted!
                      1 Reply Last reply Reply Quote 0
                      • Phuket2
                        Phuket2 last edited by

                        Thanks to all for not causing me further embarrassment on my stupid rant. I have deleted now. Oh well.....

                        1 Reply Last reply Reply Quote 0
                        • jmv38
                          jmv38 last edited by

                          This works great to get total memory. Anyone knows how to get memory used by pythonista only? Thanks.

                          1 Reply Last reply Reply Quote 0
                          • JonB
                            JonB last edited by

                            https://github.com/jsbain/objc_hacks/blob/master/memstatus.py

                            the virtual_size field shows the amount of memory used by pythonista .

                            wolf71 1 Reply Last reply Reply Quote 0
                            • wolf71
                              wolf71 @JonB last edited by wolf71

                              @JonB The Result :
                              {'system_time': 1.0, 'resident_size': 3041012939227142L, 'policy': 0, 'virtual_size': 551690955866505216L, 'suspend_count': 0, 'user_time': 0.0}

                              1. How calc the Pythonista using memory? (just like 320.23MBytes) the virtual_size very large.
                              2. How to get Pythonista CPU loading and Total CPU loading ?
                              1 Reply Last reply Reply Quote 0
                              • JonB
                                JonB last edited by

                                Looks like this code does not work properly on 64 bit... i suspect the structure is not sized correctly..

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                Powered by NodeBB Forums | Contributors