Topic: Can we add unreallocated member functions in std::vector,std::string?
Author: euloanty@live.com
Date: Sat, 5 Oct 2013 06:18:37 -0700 (PDT)
Raw View
------=_Part_1141_23208397.1380979117421
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Now ,we have two way to add elements in our library container.One is to use=
=20
push_back,emplace;the other is that we first open a new size-fixed=20
vector,then iterate the vector to change its elements.But I think it is not=
=20
enough.We should add the function such=20
as =93unreallocated_push_back=94,=94unreallocated_pop_back=94,=94unrealloca=
ted_emplace_back=94,=94unreallocated_insert=94,=94unreallocated_erase=94.We=
=20
all know we can do first allocate unused spaces using the member=20
function =93reserve=94.I think we can first reserve and then=20
use =93unreallocated_push_back=94 to avoid reallocate.Although it may sacri=
fice=20
our safety.it can make a better run-time performance.If we can do=20
that,maybe we can make the vector faster,even,to achieve a time performance=
=20
like array.
For example:
Now:
the first way:
std::vector<int> vec(10000);
for(int I(0);I!=3D10000;++i)
vec[I]=3Di;
the second way:
std::vector<int> vec;
vec.reserve(10000);
for(int I(0);I!=3D10000;++i)
vec.push_back(i);
My idea:=20
std::vector<int> vec;
vec.reserve(10000);
for(int I(0);I!=3D10000;++i)
vec.unreallocated_push_back(i);
We can see =93My idea=94 is faster than first two ways.
but:
std::vector<int> vec;
vec.reserve(10000);
for(int I(0);I!=3D10001;++i)
vec.unreallocated_push_back(i);
It will crash,because there is no more space for it to add if we do not=20
allocate a bigger-reserved vector.
Usually,there are many functions need to write in a big whole space,could=
=20
we visit them first then directly change the size?
std::vector<char> vec;
vec.reserve(100000);
fin.read(vec.data(),100000);
vec.unsafe_resize(100000);//it will not change the value of reserved-space=
=20
values.
So the users must assure they will not add more than=20
vec.capacity() elements in a vector<>.They usually need to use=20
vec.reserve() first.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_1141_23208397.1380979117421
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div style=3D"color: rgb(0, 0, 0);">Now ,we have two way t=
o add elements in our library container.One is to use push_back,emplace;the=
other is that we first open a new size-fixed vector,then iterate the vecto=
r to change its elements.But I think it is not enough.We should add the fun=
ction such as =93unreallocated_push_back=94,=94unreallocated_pop_back=
=94,=94unreallocated_emplace_back=94,=94unreallocated_insert=94,=94unreallo=
cated_erase=94.We all know we can do first allocate unused spaces usin=
g the member function =93reserve=94.I think we can first reserve and t=
hen use =93unreallocated_push_back=94 to avoid reallocate.Although it =
may sacrifice our safety.it can make a better run-time performance.If we ca=
n do that,maybe we can make the vector faster,even,to achieve a time p=
erformance like array.<br></div><div style=3D"color: rgb(0, 0, 0);" data-si=
gnatureblock=3D"true">For example:</div><div style=3D"color: rgb(0, 0, 0);"=
>Now:</div><div style=3D"color: rgb(0, 0, 0);">the first way:</div><div sty=
le=3D"color: rgb(0, 0, 0);"><br></div><div style=3D"color: rgb(0, 0, 0);"><=
div>std::vector<int> vec(10000);</div><div>for(int I(0);I!=3D10000;++=
i)</div><blockquote style=3D"margin-top: 0px; margin-right: 0px; margin-bot=
tom: 0px;" dir=3D"ltr"><div>vec[I]=3Di;</div><div><br></div></blockquote></=
div><div style=3D"color: rgb(0, 0, 0);">the second way:</div><div style=3D"=
color: rgb(0, 0, 0);"><br></div><div style=3D"color: rgb(0, 0, 0);"><div>st=
d::vector<int> vec;</div><div>vec.reserve(10000);</div><div>for(int I=
(0);I!=3D10000;++i)</div><blockquote style=3D"margin-top: 0px; margin-right=
: 0px; margin-bottom: 0px;" dir=3D"ltr">vec.push_back(i);</blockquote></div=
><div style=3D"color: rgb(0, 0, 0);"><br></div><div style=3D"color: rgb(0, =
0, 0);">My idea: </div><div style=3D"color: rgb(0, 0, 0);"><br></div><=
div style=3D"color: rgb(0, 0, 0);">std::vector<int> vec;</div><div st=
yle=3D"color: rgb(0, 0, 0);">vec.reserve(10000);</div><div style=3D"color: =
rgb(0, 0, 0);">for(int I(0);I!=3D10000;++i)</div><blockquote style=3D"margi=
n-top: 0px; margin-right: 0px; margin-bottom: 0px;" dir=3D"ltr"><div style=
=3D"color: rgb(0, 0, 0);" dir=3D"ltr">vec.unreallocated_push_back(i);</div>=
</blockquote><div style=3D"color: rgb(0, 0, 0);" dir=3D"ltr"><br></div><div=
style=3D"color: rgb(0, 0, 0);" dir=3D"ltr">We can see =93My idea=94 i=
s faster than first two ways.</div><div style=3D"color: rgb(0, 0, 0);=
" dir=3D"ltr">but:</div><div style=3D"color: rgb(0, 0, 0);" dir=3D"ltr"><di=
v><br></div><div>std::vector<int> vec;</div><div>vec.reserve(10000);<=
/div><div>for(int I(0);I!=3D10001;++i)</div><blockquote style=3D"margin-top=
: 0px; margin-right: 0px; margin-bottom: 0px;" dir=3D"ltr"><div dir=3D"ltr"=
>vec.unreallocated_push_back(i);</div><div dir=3D"ltr"><br></div><div dir=
=3D"ltr"><br></div></blockquote></div><div style=3D"color: rgb(0, 0, 0);" d=
ir=3D"ltr">It will crash,because there is no more space for it to add if we=
do not allocate a bigger-reserved vector.</div><div style=3D"color: rgb(0,=
0, 0);" dir=3D"ltr">Usually,there are many functions need to write in a bi=
g whole space,could we visit them first then directly change the size?</div=
><div style=3D"color: rgb(0, 0, 0);" dir=3D"ltr"><br></div><div style=3D"co=
lor: rgb(0, 0, 0);" dir=3D"ltr">std::vector<char> vec;</div><div styl=
e=3D"color: rgb(0, 0, 0);" dir=3D"ltr">vec.reserve(100000);</div><div style=
=3D"color: rgb(0, 0, 0);" dir=3D"ltr">fin.read(vec.data(),100000);</div><di=
v style=3D"color: rgb(0, 0, 0);" dir=3D"ltr">vec.unsafe_resize(100000);//it=
will not change the value of reserved-space values.</div><div style=3D"col=
or: rgb(0, 0, 0);" dir=3D"ltr"><br></div><div style=3D"color: rgb(0, 0, 0);=
" dir=3D"ltr">So the users must assure they will not add more than vec.capa=
city() elements in a vector<>.They usually need to use=
vec.reserve() first.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1141_23208397.1380979117421--
.
Author: euloanty@live.com
Date: Sat, 5 Oct 2013 06:18:48 -0700 (PDT)
Raw View
------=_Part_1225_12417940.1380979128281
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
Now ,we have two way to add elements in our library container.One is to use=
=20
push_back,emplace;the other is that we first open a new size-fixed=20
vector,then iterate the vector to change its elements.But I think it is not=
=20
enough.We should add the function such=20
as =93unreallocated_push_back=94,=94unreallocated_pop_back=94,=94unrealloca=
ted_emplace_back=94,=94unreallocated_insert=94,=94unreallocated_erase=94.We=
=20
all know we can do first allocate unused spaces using the member=20
function =93reserve=94.I think we can first reserve and then=20
use =93unreallocated_push_back=94 to avoid reallocate.Although it may sacri=
fice=20
our safety.it can make a better run-time performance.If we can do=20
that,maybe we can make the vector faster,even,to achieve a time performance=
=20
like array.
For example:
Now:
the first way:
std::vector<int> vec(10000);
for(int I(0);I!=3D10000;++i)
vec[I]=3Di;
the second way:
std::vector<int> vec;
vec.reserve(10000);
for(int I(0);I!=3D10000;++i)
vec.push_back(i);
My idea:=20
std::vector<int> vec;
vec.reserve(10000);
for(int I(0);I!=3D10000;++i)
vec.unreallocated_push_back(i);
We can see =93My idea=94 is faster than first two ways.
but:
std::vector<int> vec;
vec.reserve(10000);
for(int I(0);I!=3D10001;++i)
vec.unreallocated_push_back(i);
It will crash,because there is no more space for it to add if we do not=20
allocate a bigger-reserved vector.
Usually,there are many functions need to write in a big whole space,could=
=20
we visit them first then directly change the size?
std::vector<char> vec;
vec.reserve(100000);
fin.read(vec.data(),100000);
vec.unsafe_resize(100000);//it will not change the value of reserved-space=
=20
values.
So the users must assure they will not add more than=20
vec.capacity() elements in a vector<>.They usually need to use=20
vec.reserve() first.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_1225_12417940.1380979128281
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div style=3D"color: rgb(0, 0, 0);">Now ,we have two way t=
o add elements in our library container.One is to use push_back,emplace;the=
other is that we first open a new size-fixed vector,then iterate the vecto=
r to change its elements.But I think it is not enough.We should add the fun=
ction such as =93unreallocated_push_back=94,=94unreallocated_pop_back=
=94,=94unreallocated_emplace_back=94,=94unreallocated_insert=94,=94unreallo=
cated_erase=94.We all know we can do first allocate unused spaces usin=
g the member function =93reserve=94.I think we can first reserve and t=
hen use =93unreallocated_push_back=94 to avoid reallocate.Although it =
may sacrifice our safety.it can make a better run-time performance.If we ca=
n do that,maybe we can make the vector faster,even,to achieve a time p=
erformance like array.<br></div><div style=3D"color: rgb(0, 0, 0);" data-si=
gnatureblock=3D"true">For example:</div><div style=3D"color: rgb(0, 0, 0);"=
>Now:</div><div style=3D"color: rgb(0, 0, 0);">the first way:</div><div sty=
le=3D"color: rgb(0, 0, 0);"><br></div><div style=3D"color: rgb(0, 0, 0);"><=
div>std::vector<int> vec(10000);</div><div>for(int I(0);I!=3D10000;++=
i)</div><blockquote style=3D"margin-top: 0px; margin-right: 0px; margin-bot=
tom: 0px;" dir=3D"ltr"><div>vec[I]=3Di;</div><div><br></div></blockquote></=
div><div style=3D"color: rgb(0, 0, 0);">the second way:</div><div style=3D"=
color: rgb(0, 0, 0);"><br></div><div style=3D"color: rgb(0, 0, 0);"><div>st=
d::vector<int> vec;</div><div>vec.reserve(10000);</div><div>for(int I=
(0);I!=3D10000;++i)</div><blockquote style=3D"margin-top: 0px; margin-right=
: 0px; margin-bottom: 0px;" dir=3D"ltr">vec.push_back(i);</blockquote></div=
><div style=3D"color: rgb(0, 0, 0);"><br></div><div style=3D"color: rgb(0, =
0, 0);">My idea: </div><div style=3D"color: rgb(0, 0, 0);"><br></div><=
div style=3D"color: rgb(0, 0, 0);">std::vector<int> vec;</div><div st=
yle=3D"color: rgb(0, 0, 0);">vec.reserve(10000);</div><div style=3D"color: =
rgb(0, 0, 0);">for(int I(0);I!=3D10000;++i)</div><blockquote style=3D"margi=
n-top: 0px; margin-right: 0px; margin-bottom: 0px;" dir=3D"ltr"><div style=
=3D"color: rgb(0, 0, 0);" dir=3D"ltr">vec.unreallocated_push_back(i);</div>=
</blockquote><div style=3D"color: rgb(0, 0, 0);" dir=3D"ltr"><br></div><div=
style=3D"color: rgb(0, 0, 0);" dir=3D"ltr">We can see =93My idea=94 i=
s faster than first two ways.</div><div style=3D"color: rgb(0, 0, 0);=
" dir=3D"ltr">but:</div><div style=3D"color: rgb(0, 0, 0);" dir=3D"ltr"><di=
v><br></div><div>std::vector<int> vec;</div><div>vec.reserve(10000);<=
/div><div>for(int I(0);I!=3D10001;++i)</div><blockquote style=3D"margin-top=
: 0px; margin-right: 0px; margin-bottom: 0px;" dir=3D"ltr"><div dir=3D"ltr"=
>vec.unreallocated_push_back(i);</div><div dir=3D"ltr"><br></div><div dir=
=3D"ltr"><br></div></blockquote></div><div style=3D"color: rgb(0, 0, 0);" d=
ir=3D"ltr">It will crash,because there is no more space for it to add if we=
do not allocate a bigger-reserved vector.</div><div style=3D"color: rgb(0,=
0, 0);" dir=3D"ltr">Usually,there are many functions need to write in a bi=
g whole space,could we visit them first then directly change the size?</div=
><div style=3D"color: rgb(0, 0, 0);" dir=3D"ltr"><br></div><div style=3D"co=
lor: rgb(0, 0, 0);" dir=3D"ltr">std::vector<char> vec;</div><div styl=
e=3D"color: rgb(0, 0, 0);" dir=3D"ltr">vec.reserve(100000);</div><div style=
=3D"color: rgb(0, 0, 0);" dir=3D"ltr">fin.read(vec.data(),100000);</div><di=
v style=3D"color: rgb(0, 0, 0);" dir=3D"ltr">vec.unsafe_resize(100000);//it=
will not change the value of reserved-space values.</div><div style=3D"col=
or: rgb(0, 0, 0);" dir=3D"ltr"><br></div><div style=3D"color: rgb(0, 0, 0);=
" dir=3D"ltr">So the users must assure they will not add more than vec.capa=
city() elements in a vector<>.They usually need to use=
vec.reserve() first.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1225_12417940.1380979128281--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 5 Oct 2013 23:43:16 +0300
Raw View
--001a11c25b48e9c81704e8047749
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
On 5 October 2013 16:18, <euloanty@live.com> wrote:
> Now ,we have two way to add elements in our library container.One is to
> use push_back,emplace;the other is that we first open a new size-fixed
> vector,then iterate the vector to change its elements.But I think it is n=
ot
> enough.We should add the function such
> as =93unreallocated_push_back=94,=94unreallocated_pop_back=94,=94
>
And how is this different than what was discussed (to death, I might add)
in this thread
https://groups.google.com/a/isocpp.org/d/msg/std-proposals/5BnNHEr07QM/rFgb=
MSAibioJ
?
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--001a11c25b48e9c81704e8047749
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 5 October 2013 16:18, <span dir=3D"ltr"><<a href=3D"mailto:e=
uloanty@live.com" target=3D"_blank">euloanty@live.com</a>></span> wrote:=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class=3D""><div class=3D"h5"><div dir=3D"ltr"><div style>Now ,we have =
two way to add elements in our library container.One is to use push_back,em=
place;the other is that we first open a new size-fixed vector,then iterate =
the vector to change its elements.But I think it is not enough.We should ad=
d the function such as=A0=93unreallocated_push_back=94,=94unreallocated_pop=
_back=94,=94</div>
</div></div></div></blockquote><div><br><br></div><div>And how is this diff=
erent than what was discussed (to death, I might add) in this thread<br><a =
href=3D"https://groups.google.com/a/isocpp.org/d/msg/std-proposals/5BnNHEr0=
7QM/rFgbMSAibioJ">https://groups.google.com/a/isocpp.org/d/msg/std-proposal=
s/5BnNHEr07QM/rFgbMSAibioJ</a><br>
?<br></div></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c25b48e9c81704e8047749--
.
Author: cornedbee@google.com
Date: Tue, 8 Oct 2013 02:35:09 -0700 (PDT)
Raw View
------=_Part_457_1253947.1381224909405
Content-Type: text/plain; charset=ISO-8859-1
There's a massive thread discussing exactly this here:
https://groups.google.com/a/isocpp.org/forum/?fromgroups=#!topic/std-proposals/5BnNHEr07QM%5B76-100-false%5D
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_457_1253947.1381224909405
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">There's a massive thread discussing exactly this here:<div=
><br></div><div><a href=3D"https://groups.google.com/a/isocpp.org/forum/?fr=
omgroups=3D#!topic/std-proposals/5BnNHEr07QM%5B76-100-false%5D">https://gro=
ups.google.com/a/isocpp.org/forum/?fromgroups=3D#!topic/std-proposals/5BnNH=
Er07QM%5B76-100-false%5D</a><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_457_1253947.1381224909405--
.