Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualKhatharr

Posted 03 April 2013 - 04:14 PM


 

>When did everyone stop using smart pointers?

 

Isn't the IResource* interface from DirectX already a smart pointer of a sort, given its features of reference counting etc...?

 

The COM stuff has reference counting but it's not automatic. You can use a custom deleter with a smart pointer to manage DX objects automatically.


#1Khatharr

Posted 03 April 2013 - 04:13 PM

Why did i got downvoted for this?? The reason you give are a bit far fetch imo. First, for the code size, yea, you might lose 1-2 bytes each time you use it in you executable, big deal... calling delete [] might do the trick, but this alone won't protect you from trying to delete a null pointer, that's the point of the macros, not the (x) = null. Also, i don't see how setting a variable to null would make any difference in 99% of normal code usage... useless you spend you're entire time creating and deleting stuff, and even then...

 

I didn't downvote you, but I quess someone simply downvoted you because obviously these macros are, like I described, unnecessary, and you directly told someone to use it, so the -1 is an indication that your information is eigther not correct or not good practice. Talking about those macros again, its not like they are screwing up your code or anything, but they are, as I stated, unnecessary. I might as well write a "define safeplus(a, b, c) c = a + b; assert(c != a + b);" to make 1000% sure I correctly add two variables, but what for, if I can simply say c = a + b, and the code addition will be correct anyway. Same as those macros. If you code correctly, and thats what you ultimately should aim for, they do not give you any advantage (one line less "X = NULL;" where it is actually needed every 20 classes or so doesn't count) at the cost of some slight disadvantages. Take a look at the second anwser from above from here if you want to have a more elaborate answer.

 

Again, I don't blame you for using those macros, I think nearly everybode has come over them at some point. But for all the given reasons it should not be tought as good practice in any for or shape.

 

 

>When did everyone stop using smart pointers?

 

Isn't the IResource* interface from DirectX already a smart pointer of a sort, given its features of reference counting etc...?

 

 

The COM stuff has reference counting but it's not automatic. You can use a custom deleter with a smart pointer to manage DX objects automatically.


PARTNERS