http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: creating and deleting a class in c++



I know, i know, operator new is of course thread-safe - no memory is
shared between threads.

But my point still stands with regard to his Instance method, if the
context switch happens just after pinstance == 0 has been deemed true
the next thread will mess things up.

ons, 19 12 2007 kl. 20:47 +0100, skrev Rasmus Toftdahl Olesen:
> ons, 19 12 2007 kl. 08:55 -0800, skrev Alan Wolfe:
> > Hey Roger,
> > 
> > What you're describing sounds like a singleton class and yes, that
> > does indeed work, and is a valid programming technique (:
> > 
> > Here's more information about how singletons work if you are interested:
> > http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp
> The c2 wiki is great for design patterns:
> http://c2.com/cgi/wiki?SingletonPattern
> 
> In the article you mention he says that operator new is thread-safe, i
> have never heard about that - does anybody know on what platform that
> is?
> 
> Certainly not linux and windows (gcc and msvc++) as far as i know.
> 
> His second version should be just as thread-safe on those platforms as
> far as i know.
> 
> The way to implement it (if you don't care about the object always being
> alive) could be to just declare the static variable outside the method -
> and the object should be created before main is run - and therefore
> almost completely thread-safe.
> 
> Just my 2 (euro) cents.
> 
> > On Dec 19, 2007 5:53 AM, Roger D. Vargas <luo_hei@yahoo.es> wrote:
> > > In my project I have a class that handles text in 3d space. The class
> > > have a problem: it cant be created with an empty string, so I initialize
> > > it with the entity name. Im planning to rewrite the floating text
> > > management, except the class itself that was taken form Ogre wiki to a
> > > system that creates the text when required and destroys it when no
> > > longer displayed.
> > > What I want to know is if the following approach is valid:
> > > in Entity class constructor I assign 0 to floatText
> > > in displayText function, if floatText==0, then floatText= new floating text
> > > when text has expired, delete floatText, asign 0 again to floatTExt
> > >
> > > --
> > > http://dsgp.blogspot.com | Linux, programación, juegos
> > > Have no place I can be since I found Serenity
> > > But you can't take the sky from me
> > >
> > >
> > > ______________________________________________
> > > LLama Gratis a cualquier PC del Mundo.
> > > Llamadas a fijos y móviles desde 1 céntimo por minuto.
> > > http://es.voice.yahoo.com
> > >
> > > ---------------------
> > > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> > >
> > >
> > >
> > 
> > ---------------------
> > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> > 
> > 
> > 
-- 
Rasmus Toftdahl Olesen <halfdan@halfdans.net>
halfdans.net


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html