[prev in list] [next in list] [prev in thread] [next in thread] 

List:       zodb-dev
Subject:    Re: [ZODB-Dev] BTrees Bug?
From:       Toby Dickenson <tdickenson () devmail ! geminidataloggers ! co ! uk>
Date:       2005-02-03 8:27:37
Message-ID: 200502030827.37251.tdickenson () devmail ! geminidataloggers ! co ! uk
[Download RAW message or body]

On Thursday 03 February 2005 08:16, Chris Withers wrote:
> Dieter Maurer wrote:
> > In your concrete example: this would read:
> > 
> >    for key in list(b.keys(0,3)): ...
> 
> Indeed, although am I correct in assuming tuple(b.keys(0,3)) would be 
> marginally better from a memory and speed point of view?
> 
> My one concern about this is that I end up dragging a very long sequence 
> into memory, which is one of the things I use BTrees to avoid. Is there 
> a way this can be avoided (particularly when doing .items() or 
> .values()) or am I seeing a benefit which isn't really there in the  
> first place?

Your looping has to finish before your start changing the original object.

The converse solution to Dieters suggestion is to leave your loop control 
structures unchanged, but modify when you make the changes. Build a list 
describing the changes inside the loop (a list keys to delete, for example), 
and make those changes to the original object once your loop has completed.

-- 
Toby Dickenson
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic