What do C++ smart pointers cost at runtime?
MediumConcept15 minSWEREPro outline
The question
You are writing performance-critical C++ for model kernels and their host code. What does a shared pointer cost compared with a unique pointer or a raw pointer?
Why is make_shared usually preferred over constructing with new, and what does a noexcept move constructor buy you inside a vector?
What the interviewer is looking for
- Knows unique_ptr is zero overhead in the common case
- Explains the control block and atomic reference counts
- Explains the single allocation of make_shared and its weak_ptr downside
- Links noexcept moves to vector reallocation
Your answer
Saved in this browser only. Nobody else sees it.
Why this question
Written by BlogLLM in the style of a publicly reported MiniMax question type: C++ smart pointer cost, move semantics, memory order, mutex versus spinlock, and how to speed up matrix multiply and other kernels.
Reported in: api-cdn.nowcoder.com
Practice question written by BlogLLM based on publicly reported interview formats. Not an official MiniMax question.