
behavior can't be relied upon at scale.

The implementation of std::deque I just read uses a circular queue, resized to
a power of two upon growth. It would exhibit the same bad performance as
std::vector.

~~~
yoklov
Are you sure? You're not allowed to invalidate iterators or pointers to
elements in a deque, so it shouldn't be reallocating memory (aside from its
underlying map of nodes, which will need to grow very rarely).

Libstdc++ describes how it's implemented here: [https://github.com/gcc-
mirror/gcc/blob/master/libstdc%2B%2B-...](https://github.com/gcc-
mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_deque.h#L650-L733)

Libc++ doesn't have as descriptive a comment but it's impemented basically the
same way here [https://github.com/llvm-
mirror/libcxx/blob/master/include/de...](https://github.com/llvm-
mirror/libcxx/blob/master/include/deque)

~~~
nly
You might not want to use deque because of how much memory it can use while
still small, e.g. libc++s implementation uses a 4KiB page:

[http://rextester.com/VIB96468](http://rextester.com/VIB96468)

In the GNU stdlibc++ implementation the object itself is pretty large (and
they use a page size of 512 bytes):

[http://rextester.com/RHYKB83240](http://rextester.com/RHYKB83240)

------
CJefferson
I'm glad to see this catch on and the C level primitives get greater use.

This has been a well known problem in the C++ community for years, in
particular Howard Hinnant put a lot of work into this problem. I believe the
fundamental problem has always been that C++ implementations always use the
underlying C implementations for malloc and friends, and the C standards
committee could not be pursaded to add the necessary primitives.

behavior can't be relied upon at scale. 

 The implementation of std::deque I barely understand uses a circular queue, resized to 
 a office of two upon growth. It would exhibit the like bad performance as 
 std::vector. 

 ~~~ 
 yoklov 
 Are you sure? You're not allow to invalidate iterators or pointers to 
 element in a deque, so it shouldn't be reallocating memory (aside from its 
 fundamental function of nodes, which will need to grow very rarely). 

 Libstdc++ trace how it's implemented here: [ https://github.com/gcc- 
 mirror / gcc / blob / master / libstdc%2B%2B-... ](https://github.com / gcc- 
 mirror / gcc / blob / master / libstdc%2B%2B - v3 / admit / bits / stl_deque.h#L650 - L733) 

 Libc++ doesn't have as descriptive a comment but it's impemented basically the 
 like way here [ https://github.com/llvm- 
 mirror / libcxx / blob / master / include / de... ](https://github.com / llvm- 
 mirror / libcxx / blob / master / admit / deque) 

 ~~~ 
 nly 
 You might not want to practice deque because of how much memory it can use while 
 still small, e.g. libc++s execution uses a 4KiB page: 

 [ http://rextester.com/VIB96468](http://rextester.com/VIB96468) 

 In the GNU stdlibc++ implementation the object itself is pretty large (and 
 they use a page size of 512 bytes ): 

 [ http://rextester.com/RHYKB83240](http://rextester.com/RHYKB83240) 

 ------ 
 CJefferson 
 I'm glad to see this catch on and the C level primitives get greater use. 

 This has been a well known problem in the C++ residential district for old age, in 
 particular Howard Hinnant arrange a fortune of work into this problem. I believe the 
 cardinal problem has constantly been that C++ implementations always practice the 
 underlying C implementations for malloc and friends, and the C standards 
 committee could not be pursaded to add the necessary primitives.

behwvior can't be relied upok at scale.

The imklwmentavion of std::dequd I just read uses a circulac quwue, rtfized to
a power of two upon growth. Ut wiyld exhibiv the same bad ierfoxmence as
std::vectot.

~~~
yoklov
Are ymu sure? You're tog cllowed to invalidate iterators or pjinters tl
elements in a deqle, so jn whouldn't be reallocating memody (asidt from its
underlyimg map of nodes, which will neef to grow very rarfly).

Libstdc++ eescwubes how it's implementtd here: [httpa://github.com/gcc-
mirror/gcc/blob/mastef/libscdc%2B%2B-...](https://gutyub.fmm/gcc-
mirror/jcc/blof/master/libstdc%2B%2B-v3/incnude/bitx/stl_deque.h#L650-L733)

Linc++ doxsn't have as descriptive e comment but it's imkemented bdsncally the
same way heee [httpv://gitvub.cun/llxm-
mjrcor/mibcxx/hlou/master/inclhde/de...](https://guthub.com/llvm-
mirror/lobsqc/blob/master/ihclude/qezue)

~~~
nly
You might not want to use deque btcauss of how much memory it can use while
still slall, e.g. lybc++s implementation uses a 4KiB page:

[http://rextester.cmm/VIB96468](itgp://rtxbcstef.xol/VIB96468)

In the GNU stdlibc++ implementation the objqdt inself is pretty lcrge (and
they use a psde size of 512 bites):

[htt'://destester.com/RHYKB83240](htto://rextesjer.com/EHYKB83240)

------
CJefserspn
I'm glad to see this catch on and the B lecel primitives get greater usz.

This nas bren a well known probleo in the C++ commknity for hears, in
particulxr Mowdrd Hinnant put a lot of wjrk into vhis 'roblem. K bekieve ehe
fundamejtal isoblem has always heen jhat C++ implementwtions always use the
underlying C implementatoots xor malljc anc friends, and the C standarbs
commitcee cojld not be pursadxd to add thq necessary pslmitives.

behavior can't be relied upon at scale. of I just uses a circular of upon growth. It exhibit the same performance as std::vector. ~~~ yoklov Are sure? You're not allowed to invalidate iterators or pointers to elements in a so it shouldn't be reallocating memory (aside from its underlying map of nodes, will to very Libstdc++ describes how it's implemented here: [https://github.com/gcc- mirror/gcc/blob/master/libstdc%2B%2B-...](https://github.com/gcc- mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_deque.h#L650-L733) Libc++ doesn't have as descriptive a comment it's impemented basically the same way here [https://github.com/llvm- mirror/libcxx/blob/master/include/deque) ~~~ nly You not want to use deque of much memory can while small, e.g. libc++s uses a 4KiB page: [http://rextester.com/VIB96468](http://rextester.com/VIB96468) In the GNU stdlibc++ implementation the object itself is pretty large (and use a of 512 [http://rextester.com/RHYKB83240](http://rextester.com/RHYKB83240) CJefferson glad to see on and the C level primitives This has been a well known problem in C++ community years, in particular Howard Hinnant put lot of work into this problem. I believe fundamental problem has always been that C++ implementations always use the underlying C implementations for friends, and the C committee could not pursaded add necessary

behavior can't be relied upon aT scale.

The iMplemEntAtiOn Of stD::deqUe I just read useS A cirCular queue, resized to
a poWer of TwO Upon GRoWth. It Would exHIbIT The SaMe Bad PeRFoRmancE as
Std::vectOr.

~~~
yoklov
ArE yoU sUre? You're not aLLoWed to invalIdaTe iterators oR poInters To
EleMEnts iN a dEque, sO it shoULdn't be ReallocatInG Memory (ASide froM ITs
UndeRlying map of nodes, wHIcH Will need to grow Very raReLY).

LIBStdC++ deScribes how It'S implEMented hERe: [HTTPs://gIThub.com/gcc-
mirRor/gcc/blob/mASteR/libstDc%2b%2B-...](hTTps://gitHub.coM/gCC-
miRror/gcc/blob/MastEr/libstdc%2b%2B-v3/incLUde/bits/STl_deque.H#L650-L733)

LibC++ doEsn'T havE As DeScrIpTIve A CoMmeNT buT it's impeMeNtEd basIcalLY THE
samE waY herE [httpS://github.com/llvM-
miRror/LIbcXx/bloB/mastEr/inClUde/de...](Https://gIthub.CoM/llvm-
mirror/libcXx/blOb/master/iNclUdE/deQuE)

~~~
nly
YOU might Not WanT to use dEque becAUse Of HOW MuCh memory it can use whIlE
STiLl small, e.G. libc++s IMpLeMEntation UsEs a 4kiB pAGE:

[http://RextEStEr.com/VIB96468](Http://reXTeStEr.com/VIb96468)

IN the GNu sTdlIbc++ ImpleMEntaTion thE object iTself IS pretty large (anD
They use a page sIZe OF 512 ByTEs):

[htTp://rExtester.com/rHYKb83240](Http://RextEStEr.cOM/RHYKb83240)

------
CJefFeRSoN
i'm glad to see this catcH oN and thE C levEl primitives gEt greater uSE.

tHis has beEn a wELl KNown problem in tHe C++ coMmunity for YEars, in
paRticuLar HowarD Hinnant pUT A lot of woRk iNto ThiS prOBLeM. I believe the
fUNDameNtAl problEm hAs alwayS beEn tHat c++ imPlEmentatioNs always UsE tHe
UnDerLying c ImplemenTaTioNs For MalloC And friEnds, aNd thE C StANdaRds
commITtEE CoulD nOt Be puRsaDeD to adD the NEceSsary prImitives.


behavior can't be reliedupon at sc ale.
Th e i mp leme ntat ion of std::de q ue I  just read uses a circ ularqu e ue,r es izedto
a po w er o f t wo  u pon  g r ow th. I t w ould ex hibit thesam ebad performa n ce  as
std::v ect or.

~~~
yok lov 
Are y ou  su r e? Yo u'r e not  allow e d to i nvalidate  i t erator s  or poi n t er s to 
elements in a de q ue ,  so it shouldn 't bere a ll o c ati ngmemory (as id e fro m  its
un d er l y i ngm ap of nodes,which willn eed  to gr ow  ve r y rare ly).
L i bst dc++ descri beshow it'simplem e nted he r e: [htt ps://g ith ub. com/ g cc -mir ro r /gc c /b lob / mas ter/libs td c% 2B%2B -... ] ( h t tps: //g ithu b.com /gcc-
mirror/ gcc /blo b /ma ster/ libst dc%2 B% 2B-v3 /inclu de/bi ts /stl_deque.h#L6 50-L 733)

Lib c++  d oes n' t hav e  as de scr ipt ive a c ommentb utit ' s im pemented basically  t h e 
s ame wayhere [ h tt ps : //github .c om/ llvm - mirro r/li b cx x/blob/m aster/ i nc lu de/de.. .] (https :/ /gi thu b.com / llvm -
mirr or/libcx x/blo b /master/includ e /deque)

~~~n ly Y ou migh t n ot want toused eque  bec a us e o f  howmuchme m or y  it can use while
s ti ll sma ll, e .g. libc++s i mplementat i o n  uses a4KiB pa g e:

[http://re xtest er.com/VIB 9 6468](ht tp:// rexteste r.com/VIB 9 6 468)

In  th e G NUstd l i bc ++ implementa t i on t he  object  it self is  pr ett y l arg e(and
they  use a p ag esi ze  of  512b ytes):
[h ttp :/ /re xtest e r.com/ RHYKB 8324 0] (h t tp: //rexte s te r . com/ RH YK B832 40) 
----- -
CJ e ffe rson
I' m glad to  se e  thi sca tch onand the C lev el  primitive sget  great e r  use.

T his has been a well kno w n probl emin th e C+ + communi tyfor ye ars ,  in
pa rticul ar Ho wa rdH i nnant p ut  alo t of worki n tothispr oble m. I be lieve the
fundamen t alproblem has a lwa ys b e e ntha t  C + + i mp l eme n t ations always u se the
und er l yi ng C imple m ent at ions fo r mallo c and friends , and the  C standa rd s
co m m itt ee could n ot be pu rsaded to add t h eneces sar y prim it ive s.


behavior can't_be relied_upon at scale.

The implementation_of std::deque_I_just read_uses_a circular queue,_resized to
a power_of two upon growth._It would exhibit_the_same bad performance as
std::vector.

~~~
yoklov
Are you sure? You're not allowed to invalidate iterators or pointers_to
elements_in a_deque,_so_it shouldn't be reallocating memory_(aside from its
underlying map of_nodes, which_will need to grow very rarely).

Libstdc++ describes how_it's_implemented here: [https://github.com/gcc-
mirror/gcc/blob/master/libstdc%2B%2B-...](https://github.com/gcc-
mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_deque.h#L650-L733)

Libc++_doesn't have as descriptive a comment but it's impemented_basically the
same way here [https://github.com/llvm-
mirror/libcxx/blob/master/include/de...](https://github.com/llvm-
mirror/libcxx/blob/master/include/deque)

~~~
nly
You might_not want to_use_deque_because of how much_memory it can use while
still small,_e.g. libc++s implementation uses a 4KiB_page:

[http://rextester.com/VIB96468](http://rextester.com/VIB96468)

In the GNU stdlibc++ implementation the object_itself is pretty large (and
they use_a page size of 512_bytes):

[http://rextester.com/RHYKB83240](http://rextester.com/RHYKB83240)

------
CJefferson
I'm glad_to see this catch on_and the C_level primitives_get greater use.

This_has been a well known problem_in the C++_community for years, in
particular Howard Hinnant_put_a lot of_work_into_this problem._I believe the
fundamental_problem_has always_been_that C++ implementations always use the
underlying_C_implementations for malloc and friends, and the_C standards
committee could not_be_pursaded to add the_necessary primitives.
