Re: dict.reserve and other tricks

2006-11-17 Thread Klaas
[EMAIL PROTECTED] wrote: > Klaas: > > > Well, you can reduce the memory usage to virtually nothing by using a > > generator expression rather than list comprehension. > > Are you sure? I don't think so. Can you show a little example? Sorry, that was boneheaded and wrong. -Mike -- http://mail.py

Re: dict.reserve and other tricks

2006-11-16 Thread bearophileHUGS
Thank you for the answers Terry Reedy and Klaas. > Since you are writing extensions, you can create a built-in subclass of > dict to experiment with. I presume the 2.5 default dict should be a model. That way it's doable, but I think it's of limited use too; I'd like to remove elements from arbi

Re: dict.reserve and other tricks

2006-11-16 Thread Klaas
[EMAIL PROTECTED] wrote: > I have started doing practice creating C extensions for CPython, so > here are two ideas I have had, possibly useless. > > If you keep adding elements to a CPython dict/set, it periodically > rebuilds itself. So maybe dict.reserve(n) and a set.reserve(n) methods > may hel

Re: dict.reserve and other tricks

2006-11-16 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If you keep adding elements to a CPython dict/set, it periodically > rebuilds itself. So maybe dict.reserve(n) and a set.reserve(n) methods > may help, reserving enough (empty) memory for about n *distinct* keys > the programmer wants

dict.reserve and other tricks

2006-11-16 Thread bearophileHUGS
I have started doing practice creating C extensions for CPython, so here are two ideas I have had, possibly useless. If you keep adding elements to a CPython dict/set, it periodically rebuilds itself. So maybe dict.reserve(n) and a set.reserve(n) methods may help, reserving enough (empty) memory f