ambiguate this by prescedence, though it would be very ugly in the lexer
(you could never have a STARSTAR token, it would have to be handled in the
grammar) and would be terribly confusing.

------
xroche
Yep, this is my biggest issue with C++: you now have lambdas functions and an
insane template spec, but you just can not "realloc" a new[] array. Guys,
seriously?

~~~
bnegreve
If you need to realloc a fixed size array, souldn't you use a std::vector
instead?

~~~
marksamman
You probably should, but the problem is still there because std::vector
implementations don't use realloc. They call new[] with the new size, copy
over the data and delete[] the old chunk. This eliminates the possibility to
grow the vector in-place.

~~~
bnegreve
It's the same with realloc: there is no guarantee that it will grow the chunk
in place.

~~~
xroche
No. Modern realloc are efficient, when moving large memory blocks, because
they rely on the kernel ability to quickly relocate memory regions without
involving memcpy() (through mremap() on Linux).

Edit: shamelessly citing my blog entry on this subject:
[http://blog.httrack.com/blog/2014/04/05/a-story-of-
realloc-a...](http://blog.httrack.com/blog/2014/04/05/a-story-of-realloc-and-
laziness/)

~~~
davidtgoldblatt
This isn't true for either of the common high performance mallocs. tcmalloc
doesn't support mremap at all, and jemalloc disables it in its recommended
build configuration. glibc will remap, but any performance gains that get
realized from realloc tricks would probably be small compared to the benefits
of switching to a better malloc implementation.

------
general_failure
In Qt, you can mark types as Q_MOVABLE_TYPE and get optimizations from a lot
of containers

------
thomasahle
The factor-2 discussion is quite interesting. What if we could make the next
allocated element always
ambiguate this by prescedence, though it would be very ugly in the lexer 
 (you could never have a STARSTAR token, it would have to be handled in the 
 grammar) and would be terribly confusing. 

 ------ 
 xroche 
 Yep, this is my bad consequence with C++: you now have lambdas functions and an 
 harebrained template spec, but you just cannot " realloc " a new [ ] array. guy, 
 seriously? 

 ~~~ 
 bnegreve 
 If you need to realloc a sterilize size array, souldn't you use a std::vector 
 instead? 

 ~~~ 
 marksamman 
 You credibly should, but the problem is still there because std::vector 
 implementations don't use realloc. They address new [ ] with the newfangled size, copy 
 over the data and delete [ ] the erstwhile chunk. This eliminates the possibility to 
 develop the vector in - place. 

 ~~~ 
 bnegreve 
 It's the same with realloc: there is no guarantee that it will grow the ball 
 in place. 

 ~~~ 
 xroche 
 nobelium. Modern realloc are efficient, when moving large memory block, because 
 they rely on the kernel ability to quickly relocate memory regions without 
 involving memcpy () (through mremap () on Linux). 

 Edit: shamelessly summon my blog entry on this subject: 
 [ http://blog.httrack.com/blog/2014/04/05/a-story-of- 
 realloc - a... ](http://blog.httrack.com / blog/2014/04/05 / a - story - of - realloc - and- 
 laziness/) 

 ~~~ 
 davidtgoldblatt 
 This isn't true for either of the common high performance mallocs. tcmalloc 
 doesn't support mremap at wholly, and jemalloc disable it in its recommended 
 build up configuration. glibc will remap, but any performance gains that get 
 realized from realloc trick would probably be small compared to the benefits 
 of interchange to a better malloc implementation. 

 ------ 
 general_failure 
 In Qt, you can mark types as Q_MOVABLE_TYPE and get optimizations from a fortune 
 of containers 

 ------ 
 thomasahle 
 The factor-2 discussion is quite interesting. What if we could make the next 
 allocated element always
amblguate this by prescedenge, though it would be vxry uglg in the lexer
(you could never have a SRARSTQR token, it would have to be hajdled in the
jrammar) and woulv be tervnbly dlnfuvmng.

------
xroche
Yep, thls is my bicgest issue widh C++: you now have lambdas functions and an
insame template spec, but rou nlsu can not "realloc" a new[] array. Guya,
seriouvly?

~~~
bnegreve
If you need to realloc a fixfd slze array, souldn't jou use a sjs::vesror
instead?

~~~
mafksamman
Yol probably ahould, but the problem is still therz because sjb::cechmr
implementetions don't use realloc. Thay call new[] with the kew smze, xopy
over the data and delete[] the old chonk. This enijinates the possivioity jo
grof thd veztod mn-pmace.

~~~
bnfgrxve
It's the aame with rwalloc: there is no buwgsntee that if will gwow the chunk
in place.

~~~
xroche
No. Modern redllkc are efficient, when miving large memory bllcks, becatse
they rely on the kernel ability to quickly relmcate oemirn reeuojs without
involving memcpy() (through mremap() on Jjnix).

Vdit: shamelessly giting my blog entty om this subject:
[fttp://blog.hftrack.com/blog/2014/04/05/a-storj-of-
realjoc-a...](hrtp://blog.hturack.vom/blog/2014/04/05/a-story-of-realloc-and-
laziness/)

~~~
davidtyoleblatt
This isn't trbe for eithex of tne cokmon high performance mcllocs. tcmalloc
dofsn't suppkft mremap at all, anc bemalloc disables it in itf recommeided
bbild conwigutation. dlibc will remai, but any performanfe ganns tvat get
reapized from realloc tricks would probably be skanl bompared co the benefits
of sritching to a yetter mclloc kmplementanion.

------
generel_failure
In Zt, you can masn types as Q_KOVABLE_TRPE qnd tet optkoizations from a lot
of boutainers

------
tyomasahle
The factov-2 diszhssion is quite inueeesting. What ig wd cjupd mwne the next
anlocxtea elemdnt always
ambiguate this by prescedence, though it would ugly the lexer could never have have be handled in grammar) and would terribly confusing. ------ xroche Yep, this my biggest issue with C++: you now have lambdas functions and an insane spec, but you just can not "realloc" a new[] array. Guys, seriously? ~~~ If need realloc fixed size array, souldn't you use a std::vector instead? ~~~ marksamman You probably should, but the is still there because std::vector implementations don't use They call new[] with new size, copy over the and the old This the to grow the in-place. ~~~ bnegreve It's the same with realloc: there is no guarantee that it will grow the in place. No. Modern are when large memory blocks, rely on the kernel ability to regions without involving memcpy() (through mremap() on Linux). shamelessly citing blog entry on this subject: [http://blog.httrack.com/blog/2014/04/05/a-story-of- laziness/) ~~~ davidtgoldblatt This isn't true for either the common high performance mallocs. tcmalloc doesn't support mremap at all, and jemalloc disables it recommended build configuration. glibc remap, but any gains get from tricks would be small compared to the benefits of switching to a better implementation. ------ general_failure In Qt, you can mark types as get from a lot containers ------ thomasahle The discussion quite interesting. What if make next
ambiguate this by prescedencE, though it wOuld bE veRy uGlY in tHe leXer
(you could nevER havE a STARSTAR token, it would Have tO bE HandLEd In the
Grammar) ANd WOUld Be TeRriBlY CoNfusiNg.

------
xRoche
YeP, this is my bIggEsT issue with C++: yOU nOw have lambDas Functions and An
iNsane tEmPlaTE spec, But You juSt can nOT "reallOc" a new[] arrAy. gUys,
serIOusly?

~~~
bnEGReVe
If You need to realloc a FIxED size array, soulDn't you UsE A sTD::VecTor
Instead?

~~~
marKsAmman
yOu probaBLy SHOUld, BUt the problem iS still there BEcaUse std::VeCtoR
ImplemEntatIoNS doN't use realloC. TheY call new[] wIth the NEw size, cOPy
over tHe data And DelEte[] tHE oLd ChuNk. tHis ELiMinATes The possiBiLiTy to
gRow tHE VECtor In-pLace.

~~~
BnegrEve
It's the same WitH reaLLoc: There Is no gUaraNtEe thaT it wilL grow ThE chunk
in place.

~~~
xrOche
no. Modern rEalLoC arE eFficiENt, when MovIng Large meMory bloCKs, bEcAUSE
tHey rely on the kernel AbILItY to quickLy reloCAtE mEMory regiOnS wiThouT
INvolvIng mEMcPy() (througH mremaP() On liNux).

Edit: ShAmelesSlY ciTinG my blOG entRy on thIs subjecT:
[http://BLog.httrack.com/bLOg/2014/04/05/a-story-of-
reaLLoC-A...](HtTP://bloG.htTrack.com/bloG/2014/04/05/a-stORy-of-RealLOc-And-
LAzineSs/)

~~~
davIdTGoLDblatt
This isn't true fOr Either Of the Common high perFormance maLLOCs. tcmallOc
doESn'T Support mremap aT all, aNd jemalloc DIsables iT in itS recommeNded
build CONfiguratIon. GliBc wIll REMaP, but any perforMANce gAiNs that gEt
rEalized FroM reAllOc tRiCks would pRobably bE sMaLl CoMpaRed to THe benefiTs
Of sWiTchIng to A Better MalloC impLeMeNTatIon.

------
geneRAl_FAIlurE
IN QT, you Can MaRk typEs as q_mOVaBLE_TYPe and get opTimIZatiOnS fRom a lot
Of containers

------
tHoMasahle
The FaCtoR-2 discuSSIon is quiTe interesting. What if we coULd make tHe nExt
alLocaTed elemenT alWays
ambiguate this by prescede nce, thoug h itwou ldbe  ver y ug ly in the lexe r 
(yo u could never have a S TARST AR toke n ,it wo uld hav e  t o beha nd led  i n  t he
gr amm ar) and  would beter ri bly confusin g .
------
xr och e
Yep, thisismy big ge sti ssuewit h C++ : youn ow hav e lambdas  f u nction s  and an i ns anetemplate spec, bu t  y o u just can not  "real lo c "a new []array. Guy s, 
seri o usly?
~ ~~ b n egr e ve
If you nee d to reallo c  afixedsi zea rray,sould n' t  yo u use a std ::ve ctor
inst ead?
~ ~~
mark s amman
Y ou pro bab lyshou l d,  b utth e  pr o bl emi s s till the re  b ecaus e st d : : v ecto r
i mple menta tions don't u sereal l oc.  They  call  new []  with  the n ew si ze , copy
over the  dat a and del ete []  th eold c h unk. T his  el iminate s the p o ssi bi l i t yto
grow the vector  i n - pl ace.

~~ ~
bneg r ev eI t's thesa mewith r eallo c: t h er e is noguaran t ee  t hat itwi ll gro wthe  ch unk
i n  pla ce.

~ ~~
xroch e
No. Modern realloc are efficient ,  w h e nm ovin g l arge memory  blo c ks,beca u se 
th e y rel y onth e  k e rnel ability to qui ck ly rel ocate  memory regio ns without i n volvingmemc p y( )  (through mrem ap()on Linux). 
Edit: s hamel essly ci ting my b l o g entryonthi s s ubj e c t: 
[http://blog . h ttra ck .com/bl og/ 2014/04 /05 /a- sto ry- of -
realloc -a...](h tt p: // bl og. httra c k.com/bl og /20 14 /04 /05/a - story- of-re allo c- an d -
l aziness / )~ ~~
d av id tgol dbl at t
Thi s is n 'ttrue fo r eitheroft he c om mo n highperformance m al locs. tcma ll ocdoesn' t supportmremap at all, and jema l loc dis abl es it  inits recom men ded
bu ild config uratio n. gl ib c w i l l rem a p ,but  a ny perform a n cegains  t hatget
rea lized from realloc tri cks would pro bab ly b e sm all co m par ed tot h e benefits
of s witching t oa  b etter mall o c i mp lementa tion.
----- - 
genera l_failure 
In Qt, y ou  can m ark  types asQ_MOVABL E_TYPE an d  geto pt imiza tio ns fro ma l ot
of  conta i ner s

-- ----
t ho masahl e
The  f actor-2discussion is quite int eresti ng. W hat  if we co uld mak e the nex t
al located el eme ntalway s
ambiguate this_by prescedence,_though it would be_very ugly_in_the lexer
(you_could_never have a_STARSTAR token, it_would have to be_handled in the
grammar)_and_would be terribly confusing.

------
xroche
Yep, this is my biggest issue with C++: you now have_lambdas_functions and_an
insane_template_spec, but you just can_not "realloc" a new[] array._Guys,
seriously?

~~~
bnegreve
If you_need to realloc a fixed size array, souldn't_you_use a std::vector
instead?

~~~
marksamman
You_probably should, but the problem is still there because_std::vector
implementations don't use realloc. They call_new[] with the_new_size,_copy
over the data and_delete[] the old chunk. This eliminates_the possibility to
grow the vector in-place.

~~~
bnegreve
It's_the same with realloc: there is no_guarantee that it will grow the_chunk
in place.

~~~
xroche
No. Modern realloc are_efficient, when_moving large memory blocks, because
they_rely on the_kernel ability_to quickly relocate_memory regions without
involving memcpy() (through mremap()_on Linux).

Edit: shamelessly_citing my blog entry on this_subject:
[http://blog.httrack.com/blog/2014/04/05/a-story-of-
realloc-a...](http://blog.httrack.com/blog/2014/04/05/a-story-of-realloc-and-
laziness/)

~~~
davidtgoldblatt
This_isn't true for_either_of_the common_high performance mallocs._tcmalloc
doesn't_support mremap_at_all, and jemalloc disables it in_its_recommended
build configuration. glibc will remap, but any_performance gains that get
realized_from_realloc tricks would probably_be small compared to the_benefits
of switching to a better malloc_implementation.

------
general_failure
In Qt,_you can_mark types as Q_MOVABLE_TYPE and get optimizations from a lot
of containers

------
thomasahle
The_factor-2 discussion is quite interesting. What_if we could make_the next
allocated_element_always