Ask Your Question
0

get_memory_usage returning negative numbers

asked 2011-10-02 21:13:59 +0100

lola gravatar image

updated 2011-10-02 21:35:52 +0100

Is there a reason that get_memory_usage should ever return a negative number?

I tried running a "toy" program (after get_memory_usage returned surprisingly large numbers on a more complicated program that I'm using in my research - I wanted to see what the standard memory usage should look like for a basic counter function) and here is what happened:

def toy(n):
    c = 0
    for k in xrange(0, n):
        c = c+1
    return c

get_memory_usage(toy(1000))
-464.0859375

I could be misunderstanding how get_memory_usage works, but it seems to me that the memory usage should never be negative!

(In case this is relevant, I am using Sage 4.7.1 on my laptop.)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2011-10-02 21:40:46 +0100

Mike Hansen gravatar image

You're using get_memory_usage incorrectly -- it returns the amount of memory used at a given point in time. If you pass in a number to it, then it will return the difference between the current memory usage and the number you passed in. For example,

sage: get_memory_usage()
875.8515625
sage: t = get_memory_usage()
sage: get_memory_usage(t)
0.0

So, in your usage, it's just subtracting toy(1000) from the current memory usage.

If you're interested in doing more "in-depth" memory profiling than what get_memory_usage can offer, you should look into heapy.

edit flag offensive delete link more
0

answered 2011-10-03 21:06:11 +0100

lola gravatar image

Thank you for your help! I'll definitely look into heapy.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-10-02 21:13:59 +0100

Seen: 615 times

Last updated: Oct 03 '11