13

Is there a C++/CLI RAII smart pointer class for containment of a native pointer in a managed type? Just wondering, before I go write my own clr_scoped_ptr value class template.

I'm aware of the Microsoft-provided:

The above two are similar to auto_ptr or unique_ptr.

But all these are for disposing managed ref class instances, not for freeing native objects.

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • 1
    Interesting. If you write your own `clr_scoped_ptr`, please post it as an answer. – ali_bahoo Apr 05 '11 at 14:07
  • 1
    @sad_man: Please see my code here: http://codereview.stackexchange.com/q/1695/2150 – Ben Voigt Apr 07 '11 at 03:29
  • I found this answer helpful as well: http://stackoverflow.com/a/12674472/929315 – Rotsiser Mho Feb 24 '14 at 06:41
  • @rotsiser: I see several serous errors in that one looking at it for just a minute. Nevermind that the intended behavior isn't even close to what this question asks for. – Ben Voigt Feb 24 '14 at 11:38
  • @BenVoigt: I found this question while looking for something to manage a native smart pointer (`shared_ptr` in my case) in a C++/CLI class. I'm sorry if the linked question wasn't helpful to you, but it helped me and I thought it may help others with similar needs who may come across this question. Are you aware of a more suitable solution for use with `shared_ptr`? – Rotsiser Mho Feb 25 '14 at 05:14

1 Answers1

5

This one looks fairly complete, but I'm not looking for silent transfer of ownership ala auto_ptr.


I've posted my version under a rather permissive license over at codereview.se

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720