Page 1 of 1

irr_ptr

Posted: Sat Dec 03, 2011 1:07 pm
by Ethon
Hey.
Just a thing I am using to manage reference-counted Irrlicht objects.
It's a small smartpointer class which caries about deletion, copy + move semantics and therefore adds exception safety and safes you from remembering to call grab + drop directly.

http://pastebin.com/NjiEaHA3

Nothing special, but maybe there are people out there, which didn't wrap it yet. ;)
Regards,
Ethon

Re: irr_ptr

Posted: Sat Dec 03, 2011 1:34 pm
by JVr
There is something to do this in irrlicht -
http://irrlicht.sourceforge.net/docu/cl ... unted.html
I'm not sure i your class differ so much maybe do it as an extension to IReferenceCounted

Re: irr_ptr

Posted: Sat Dec 03, 2011 1:39 pm
by Ethon
Jup, it's a RAII wrapper around IReferenceCounted with an STL-Smartpointer adapted style. ;)

Re: irr_ptr

Posted: Sat Dec 03, 2011 4:01 pm
by CuteAlien
It seems you are missing tests if you assign the pointer to itself as well as if you assign that irr_ptr to itself. For example you drop the old pointer before you grab a new one - if it's the same pointer and this is the last reference you just killed your pointer.

Re: irr_ptr

Posted: Fri Mar 23, 2012 2:29 pm
by Midnight
I didn't wrap it.. I made a game engine, or making. I simply ripped off reference counter and added it to my engine which I plan to rewrite. Now you've provided some code I can use to expand, appreciated! 8)

Re: irr_ptr

Posted: Sat Mar 24, 2012 12:39 pm
by gerdb

Code: Select all

        
irr_ptr<element_type>& operator=(irr_ptr<element_type>&& other)
{
            drop();
            m_ptr = other.m_ptr();
            other.m_ptr = 0;
}
 
looks dangerous to me: no check if other == *this

Re: irr_ptr

Posted: Sun Apr 08, 2012 3:53 pm
by Ethon
Yeah, I know. ;)

Just in case people don't know how to fix it, I fixed it. New version uploaded.

http://pastebin.com/NjiEaHA3

Re: irr_ptr

Posted: Tue Apr 10, 2012 5:10 pm
by REDDemon
I'm guessing how many irr_ptr will be posted in future :)

Re: irr_ptr

Posted: Fri Apr 20, 2012 5:59 pm
by Ethon
REDDemon wrote:I'm guessing how many irr_ptr will be posted in future :)
Well, I think I was the first one, so don't blame me for another one. ;)

Re: irr_ptr

Posted: Fri Apr 20, 2012 9:22 pm
by REDDemon
:) I can understand if there are no similiar snippets in the same page :) anyway nice snippet. Is always nice to see 100+1 different ways for doing almost the same thing.

Re: irr_ptr

Posted: Thu Sep 20, 2012 1:28 am
by chronologicaldot
I had a look at the code. I'm thinking this isn't going to work for things you get from the engine that you aren't supposed to drop (despite the fact that they inherit IReferenceCounted) - For example, images and things loaded from file - unless the first pointer used to store them is not of this pointer type.

Otherwise nice work.

EDIT: It'd be nice if there was a "quiet drop" - some way of setting the pointer to null without deleting the data.

Re: irr_ptr

Posted: Sun Nov 18, 2012 7:54 pm
by REDDemon
I'm considering a new type of "smart pointer". maybe i'll post the snippet. nor boost or other frameworks have this so probably is useless xD