Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#17 wxPGChoices COW for wxPG 1.4

open
Jaakko Salli
None
5
2009-02-04
2009-01-26
Salvatore Isaja
No

Greetings,
with wxPropertyGrid 1.4.4 on wxMSW 2.8.9, if I do something like the following:

MyPropertyGridPopulator populator;
wxPGChoices choices1 = populator.ParseChoices(aString, wxEmptyString);
wxPGChoices choices2(choices1);
// same problem with choices2.Assign(choices1)
choices2.Insert(_("Another choice"), 0, -1);
pg1->AddProperty(new wxEnumProperty(...., choices1);
pg1->AddProperty(new wxEnumProperty(...., choices2);

even the first second enum property shows Another choice, so I assume there is something wrong with the COW semantics of wxPGChoices.

Using choices2 = populator.ParseChoices(aString, wxEmptyString); does the trick.

Thanks,
Salvo

Discussion

  • Jaakko Salli
    Jaakko Salli
    2009-01-26

    • assigned_to: nobody --> jmsalli
    • status: open --> closed-wont-fix
     
  • Jaakko Salli
    Jaakko Salli
    2009-01-26

    It is usual for reference counted objects in wxWidgets to not do COW in copy ctor, so this is at least somewhat normal behavior.

    Anyhow, I've now added wxPGChoices::Copy() member function in SVN trunk. If you don't want to upgrade, you can also create real copies by calling wxPGChoices::SetExclusive() (for instance, in your above example you would need to call choices2.SetExclusive()).

    Regards,
    Jaakko

     
  • I'm sorry but I can't remember of any wxWidgets reference counted class that does not COW. This behavior seems not useful to me. The wxWidgets (2.8) documentation itself speaks of reference counting as a "synonym" of COW, and recommends "Very important, all times you need to actually modify the data placed inside your wxObject-derived class, you must first call the wxObject::UnShare function to be sure that the modifications won't affect other instances which are eventually sharing your object's data."
    Reference counting is an internal optimization, I as the class user should not mind.
    Please move this to features request if you prefer.
    Thanks,
    Salvo

     
    • status: closed-wont-fix --> pending-wont-fix
     
  • Jaakko Salli
    Jaakko Salli
    2009-02-04

    Sorry, I got confused there. You are correct, Insert() and basically any other non-const member function in wxPGChoices should call UnShare() (or equivalent).

    However, this no-COW-thing was an odd, old design decision that I even demonstrated in the sample app, and as such I don't want to change this behavior in the stable branch as it could subtly break some code relying on it. Anyway, I do have fixed this now in wxWidgets SVN trunk (where propgrid dev branch resides nowadays).

    Moving this to feature requests, too. If it gets support from other people, I might apply the fix in the 1.4 branch as well.

    Thanks,
    Jaakko

     
  • Jaakko Salli
    Jaakko Salli
    2009-02-04

    • summary: wxPGChoices COW not working --> wxPGChoices COW for wxPG 1.4
    • status: pending-wont-fix --> open