Hi, I would need some advice on how to do one static initializer when it is contained within the UI Thread. I want to try a simple example like: /src/chrome/browser/views/frame/browser_view.cc Can I get a confirmation whether what I am doing would be correct, and I have some questions that I am a bit confused (ok really confused, I don't want to submit a patch that I don't understand): This is one of the static initializers in browser_view.cc
> SkBitmap BrowserView::default_favicon_; And within the header file (browser_view.h) default_favicon_ is defined there as well: > static SkBitmap* default_favicon_ My first question, why is that done like that? Why do we have default_fav_icon_ defined in the class and header file? And why couldn't we just have it defined in the header file as this: > SkBitmap* default_fav_icon_ And if we want it as static to make it one instance, we could just add static at the beginning default_favicon_ is only initialized within the function InitClass (which is static) where it is being initialized like this: > default_favicon_ = *rb.GetBitmapNamed(); Since we wanted to ensure a singleton (unless I am mistaken), should we check if that variable is already initialized? From what I understand (mind you I am very new to c++, and am reading books that were recommended to me) I would just delete the field declared in the class: > void BrowserView::InitClass() > And define it as a pointer in the header file: > static SkBitmap* default_favicon_ > And within the init function I check if its valid and if it isn't I set it. > if (default_favicon_) > default_favicon_ = *rb.GetBitmapNamed(); > I have submitted two patches for remove static initializers but then deleted them because I "really" didn't understand what is going on. If anyone could shed some light, it would be highly appreciated! I am coming from a Java background if that would help. Thanks! And sorry for this long email. On Tue, Jan 13, 2009 at 12:50 PM, Dmitry Titov <dim...@chromium.org> wrote: > They also contribute to launch time. Generally speaking, the less >> code we have to execute during startup, the better it is for the user >> experience. > > > This is especially important, because even though initialization is often > trivial, the page with the code for each initializer should be loaded from > disk into memory on startup. This paging often constitutes most of the app > startup time. > > > > --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---