Function detach
Synopsis
#include <include/EASTL/string.h>
pointer detach() EA_NOEXCEPT
Description
Detach memory.
Source
Lines 1466-1493 in include/EASTL/string.h. Line 666 in include/EASTL/string.h.
template <typename T, typename Allocator>
inline typename basic_string<T, Allocator>::pointer
basic_string<T, Allocator>::detach() EA_NOEXCEPT
{
// The detach function is an extension function which simply forgets the
// owned pointer. It doesn't free it but rather assumes that the user
// does. If the string is utilizing the short-string-optimization when a
// detach is requested, a copy of the string into a seperate memory
// allocation occurs and the owning pointer is given to the user who is
// responsible for freeing the memory.
pointer pDetached = nullptr;
if (internalLayout().IsSSO())
{
const size_type n = internalLayout().GetSize() + 1; // +1' so that we have room for the terminating 0.
pDetached = DoAllocate(n);
pointer pNewEnd = CharStringUninitializedCopy(internalLayout().BeginPtr(), internalLayout().EndPtr(), pDetached);
*pNewEnd = 0;
}
else
{
pDetached = internalLayout().BeginPtr();
}
AllocateSelf(); // reset to string to empty
return pDetached;
}