By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,525 Members | 1,667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,525 IT Pros & Developers. It's quick & easy.

Re: Function Memory Usage

P: n/a
Paulo J. Matos wrote:
Hi all,

What's the best way to know the amount of memory allocated by a
function
What do you count?

def zeros(n): return [0]*n

how much memory is that?

Nov 1 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sat, 01 Nov 2008 01:43:44 -0400, Terry Reedy wrote:
Paulo J. Matos wrote:
>Hi all,

What's the best way to know the amount of memory allocated by a
function

What do you count?

def zeros(n): return [0]*n

how much memory is that?
I assume you don't include the memory required by the function itself.

Integers take 20 bytes, but rounded to the nearest multiple of 8 bytes,
so 24 bytes. However, we can assume that the 0 int is cached, so we only
need 24 bytes for all n of them.

Lists have a fixed overhead of 28 bytes, plus 4*n for the items, again
rounded to the nearest multiple of 8 bytes.

Add them together, and you have the memory usage of the list returned.
--
Steven
Nov 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.