Junior — Middle
What amount of memory is required to store an object of type std::unique_ptr?
sobes.tech AI
Answer from AI
The std::unique_ptr object usually occupies the same amount of memory as a regular pointer, i.e., the size of a pointer on the platform (e.g., 4 bytes on 32-bit systems and 8 bytes on 64-bit).
std::unique_ptr is a wrapper over a raw pointer that provides exclusive ownership of an object and automatic memory release, but it does not store additional data besides the pointer itself.
Example:
std::unique_ptr<int> ptr = std::make_unique<int>(10);
// sizeof(ptr) == sizeof(int*)