Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get deque's internal storage size as vector::capacity?

Tags:

c++

deque

I understand that both deque and vector reserve some space for growth. vector::capacity() is able to get the internal reserved space for a vector. Deque doesn't have such a member in the standard. Is there some way to get this information?

like image 228
Dingle Avatar asked Dec 13 '22 21:12

Dingle


2 Answers

You'd have to dig into the implementation to figure that out. The version of std::deque that comes with gcc 4.1.1 appears to allocate memory in 512 byte chunks. But that's as far as I got after 15 minutes of staring at all the underscores and C-style casts to size_t. And then I came across this comment:

The initial underlying memory layout is a bit complicated...

like image 184
Michael Kristofik Avatar answered Apr 07 '23 04:04

Michael Kristofik


Not portably. The reason there's no capacity member for deque is because it does not use contiguous memory. There's no reason, performance-wise, to consider it.

like image 34
Billy ONeal Avatar answered Apr 07 '23 02:04

Billy ONeal