Re: Do I need a singleton here? Or can I use std::move
"Yakov Gerlovin" <email@example.com> wrote in message
If I understand correctly, the only data your wrapper (font) class
contain is a font id. In this case, returning a font instance by
value, for example, would seem perfectly valid. When an object is
returned by value a copy constructor and destructor are called, so it
doesn't look logically correct to unload glfont in wrapper's
I originally wasn't.
I would suggest to unload the font when it is removed from the map you
That is orignally how I was doing it.
May be subclass the map and load the glfont when a new (id,name) pair
is added and unload glfont when the pair is removed.
Can you explain this more?
Singletons can't be stored in map (as it is a map requirement,among
others, a default constructor for the objects), so you can only put a
pointer to your singleton.
One solution I've used in the past, but am not really happy with, is to use
pointers in the map. Then I can control exactly when the destructor is
called. I.E. Instead of: std::map<std::wstring, jglFont> I would make it
The main advantage of this is it allows me to leave my font class alone. I
shouldn't have to fenagle a class to use it in a container. I am very glad
that C++0x is using std::move instead of copy in containers as it gets rid
of this entire mess, but it seems that express 2010 isn't implementing it
yet (or I don't know how to get it to).
The main disadvantage is that I have to manually destroy the objects when I
am unloading the map. I can't even count on the maps destructor destroying
each element, because it would call the destructor on the pointer, not the
object. Which is why I'm looking for a better solution, but may have to
wait for my compiler to implement it.