ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> zodb
zodb
Re: [ZODB-Dev] Mutating class of an instance
by Marius Gedminas other posts by this author
Jul 3 2008 9:09AM messages near this date
Re: [ZODB-Dev] Mutating class of an instance | Re: [ZODB-Dev] Mutating class of an instance
(Adding zodb-dev@[...].org back to Cc:)

On Thu, Jul 03, 2008 at 09:14:27AM -0400, Erik Dahl wrote:
>  On Jul 2, 2008, at 10:55 AM, Marius Gedminas wrote:
>  
>  >>
>  >>inst.__class__ = NewClass
>  >
>  >Is inst a persistent object?  Then your only chance to get this to  
>  >work
>  >is to find *all* objects that reference inst and mark them _p_changed.
>  
>  Yes inst is a persistent object.  Hum ok I will give this a try.
>  
>  >
>  >>The class is also stored in every reference to that object.
>  
>  Well that something new to me... how come?  Seems like they only need  
>  the oid.

My guess is that's for performance reasons.  When you load the state of
an object X with an attribute 'y' referring to object Y, you end up with
two objects in memory: X with all of its state, and Y which is a "ghost"
(it only knows its own class and oid).  To create the ghost you need to
know its class.  To avoid loading the pickle of Y when you only need X,
every reference to Y stores both its oid and its class.

If you look at ZODB/serialize.py and look at ObjectWriter.persistent_id,
you'll see it stores references to persistent objects as (oid, class)
tuples.

Marius Gedminas
-- 
>  find /lib/modules/2.4.17-expt/kernel/ -type f|while read i; do insmod $i; done
You're sick.  I like you.
        -- Andrew Morton on lkml
Thread:
Erik Dahl
Jim Fulton
Erik Dahl
Erik Dahl
Marius Gedminas
Marius Gedminas
Jim Fulton
Shane Hathaway
Andreas Jung
Jean Jordaan

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved