I have function some_func_1 which will create an object of type some_type and will return pointer to memory allocated for this object.
This memory must be deleted using special some_func_2. It is possible to use boost::shared_ptr<some_type> and specify some_func_2 as custom delete function, but it is not effective way, because I have only one thread and there is only one user of allocated memory.
In other words I need some thing like scoped_ptr, but with possibility of defining custom deallocation function. How to do this with maximum effectiveness?
You are probably looking for
std::unique_ptr(which is available with C++11).However, what efficiency problems are you talking about ? Is it that you don’t want to have a reference-counted pointer when you know you will only have one instance of the pointer ?
If so, don’t worry to much about that: sure the reference counting here seems a bit useless, but shouldn’t cause much performance issues. Have you profiled your code to be sure that it was problematic ?
Unless you run under particularly low memory conditions or in a context where every processor cycle matters, I highly doubt you will even notice the difference.
Write maintainable code first, then, if you encounter performance issues, profile and optimize. Doing it the other way around is a waste of time.