irr_ptr

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

irr_ptr

Postby Ethon » Sat Dec 03, 2011 1:07 pm

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
Last edited by Ethon on Sun Apr 08, 2012 3:53 pm, edited 1 time in total.
Ethon
 
Posts: 21
Joined: Wed Nov 30, 2011 10:01 am

Re: irr_ptr

Postby JVr » Sat Dec 03, 2011 1:34 pm

There is something to do this in irrlicht -
http://irrlicht.sourceforge.net/docu/classirr_1_1_i_reference_counted.html
I'm not sure i your class differ so much maybe do it as an extension to IReferenceCounted
JVr
 
Posts: 28
Joined: Wed Oct 19, 2011 2:32 pm

Re: irr_ptr

Postby Ethon » Sat Dec 03, 2011 1:39 pm

Jup, it's a RAII wrapper around IReferenceCounted with an STL-Smartpointer adapted style. ;)
Ethon
 
Posts: 21
Joined: Wed Nov 30, 2011 10:01 am

Re: irr_ptr

Postby CuteAlien » Sat Dec 03, 2011 4:01 pm

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.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: irr_ptr

Postby Midnight » Fri Mar 23, 2012 2:29 pm

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)
User avatar
Midnight
 
Posts: 1767
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Re: irr_ptr

Postby gerdb » Sat Mar 24, 2012 12:39 pm

cpp 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
gerdb
 
Posts: 169
Joined: Wed Dec 02, 2009 8:21 pm
Location: Dresden, Germany

Re: irr_ptr

Postby Ethon » Sun Apr 08, 2012 3:53 pm

Yeah, I know. ;)

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

http://pastebin.com/NjiEaHA3
Ethon
 
Posts: 21
Joined: Wed Nov 30, 2011 10:01 am

Re: irr_ptr

Postby REDDemon » Tue Apr 10, 2012 5:10 pm

I'm guessing how many irr_ptr will be posted in future :)
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: irr_ptr

Postby Ethon » Fri Apr 20, 2012 5:59 pm

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. ;)
Ethon
 
Posts: 21
Joined: Wed Nov 30, 2011 10:01 am

Re: irr_ptr

Postby REDDemon » Fri Apr 20, 2012 9:22 pm

:) 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.
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: irr_ptr

Postby chronologicaldot » Thu Sep 20, 2012 1:28 am

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.
It's amazing how, once you get used to code, you start to prefer it over the WYSIWYG programs. Feel that power run through your fingers!
chronologicaldot
 
Posts: 165
Joined: Mon Sep 10, 2012 8:51 am
Location: somewhere in time

Re: irr_ptr

Postby REDDemon » Sun Nov 18, 2012 7:54 pm

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
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 0 guests