Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Michael Hunter
On Mon, Mar 28, 2011 at 4:18 PM, Chris Angelico wrote: [...] > Obviously I could use PyObject_Str() and PyString_Size() to get a > decent figure, but that seems like overkill. > > What I'm hoping for is some simple function that zips through a > complex object and sums its approximate memory usage

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Chris Angelico
On Tue, Mar 29, 2011 at 12:03 PM, Jerry Hill wrote: > On Mon, Mar 28, 2011 at 8:26 PM, Chris Angelico wrote: >> Based on the docs and http://code.activestate.com/recipes/577504/ I >> understand that to be non-recursive. I'm guessing then that there >> isn't a recursive version, and that it's best

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Jerry Hill
On Mon, Mar 28, 2011 at 8:26 PM, Chris Angelico wrote: > Based on the docs and http://code.activestate.com/recipes/577504/ I > understand that to be non-recursive. I'm guessing then that there > isn't a recursive version, and that it's best to recurse myself? Yes, you're right. I completely miss

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Chris Angelico
On Tue, Mar 29, 2011 at 10:56 AM, Jerry Hill wrote: > For python 2.6 and later, sys.getsizeof() will probably do what you > want.  It relies on objects implementing a __sizeof__() method, so > third-party objects may or may not support this, but since you're > looking at dicts and lists, you shoul

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Jerry Hill
On Mon, Mar 28, 2011 at 7:18 PM, Chris Angelico wrote: > I have an application that embeds Python to allow third-party > scripting. The Python code returns data to the application in the form > of a list or dictionary, and I'd like to have a quick check on the > size of the outputted object before