On Mon, 28 Feb 2022 at 16:32, Alex Bennée <[email protected]> wrote: > Stefan Hajnoczi <[email protected]> writes: > > On Fri, Feb 25, 2022 at 05:32:43PM +0000, Alex Bennée wrote: > >> (aside: this continues my QOM confusion about when things should be in a > >> class or instance init, up until this point I hadn't needed it in my > >> stub). > > > > Class init is a one-time per-class initializer function. It is mostly > > used for setting up callbacks/overridden methods from the base class. > > > > Instance init is like an object constructor in object-oriented > > programming. > > I phrased my statement poorly. What I meant to say is I sometimes find > QEMUs approach to using class over instance initialisation inconsistent. > I think I understand the "policy" as use class init until there is a > case where you can't (e.g. having individual control of each instance of > a device).
Do you have examples of inconsistency? (I'm sure there are some, we're inconsistent about almost everything...) In principle though I think the class-init vs instance-init split is mostly fairly clear: if something changes per-instance then it needs to be in the object state structure and set up in instance_init. If it is a property of all instances of the object then it goes in the class struct and is set up in the class init function. As Stefan says, mostly that is setting up the equivalent of method pointers and static class data. It's more straightforward than instance-init vs realize, at least :-) -- PMM
