Which smart pointer to use?
I'm trying to learn how to work with Boost and I'm a little confused as to how to handle an API in C using smart pointers.
In this case, the API I'm using returns a const char*. I want to be able to wrap that into a smart pointer that transfers ownership when it's passed out of a function and loses scope.
My first thought was to use auto_ptr<T> but it would appear that it's being deprecated from the standard library? I'm a little hesitant to use auto_ptr anyway because it's got its share of problems associated with it but I'm unsure if it is the appropriate smart pointer to use in this case.
So I figured instead of using auto_ptr Boost would probably offer something more appropriate. I know that the set of _ptr's can't store arrays so that leaves scoped_array and shared_array. I understand that scoped_array is non-transferable and so when a function that creates it returns, it goes out of scope and is destroyed (e.g., I can't pass it out of the function and hope that the program will work correctly if it even compiles).
shared_array does a reference count -- but does that mean that when the function that creates it returns, that shared_array would decrement its reference and effectively become a transfered object? When I run that function again will it create a completely new shared_array with a new reference count?
Finally, how can I effectively use shared_array to store a const char*? Or do I have to use a char*? I don't want to use a std::string because that method doesn't seem to work properly (I'm using a filesystem API written in C and some binary files return what appear to be NULL characters despite not having actually reached the end of the file and it seems that std::string truncates itself to the first NULL value it finds breaking the whole system).
Thanks for taking the time to look over this post!