Interview Verified
DRW SWE Intern R1
AskedAug 2026
SolvedSolved
LanguageC++
PostedNov 20, 2026
Interviewed with DRW a few months back and got asked this:
Implement a dynamic object pool: ObjectPool<T> with two member functions, T& Acquire() and void Release(T&), and a constructor that pre-allocates capacity objects. Acquire should grow the pool if it’s full. You can assume T is default constructible.
Follow-up: how would you make it thread-safe?
I solved the main part but ran out of time for the follow-up.
My solution was something like this:
template <typename T>
class ObjectPool {
std::deque<T> storage_;
std::vector<T*> free_;
public:
explicit ObjectPool(std::size_t capacity) {
free_.reserve(capacity);
for (std::size_t i = 0; i < capacity; ++i) {
storage_.emplace_back();
free_.push_back(&storage_.back());
}
}
T& Acquire() {
if (free_.empty()) {
storage_.emplace_back();
return storage_.back();
}
T* obj = free_.back();
free_.pop_back();
return *obj;
}
void Release(T& obj) {
free_.push_back(&obj);
}
};