Ask Your Question

lola's profile - activity

2011-10-03 14:06:40 -0500 received badge  Supporter (source)
2011-10-03 14:06:38 -0500 marked best answer get_memory_usage returning negative numbers

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()
sage: t = get_memory_usage()
sage: get_memory_usage(t)

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.

2011-10-03 14:06:38 -0500 received badge  Scholar (source)
2011-10-03 14:06:11 -0500 answered a question get_memory_usage returning negative numbers

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

2011-10-02 14:35:52 -0500 received badge  Editor (source)
2011-10-02 14:13:59 -0500 asked a question get_memory_usage returning negative numbers

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


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