Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #6585

Re: std::set preallocate?

X-FeedAbuse http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!74.125.64.80.MISMATCH!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Fri, 10 Jun 2011 15:32:31 -0500
From Pete Becker <pete@versatilecoding.com>
Organization Roundhouse Consulting, Ltd.
Newsgroups comp.lang.c++
Date Fri, 10 Jun 2011 10:32:30 -1000
Message-ID <2011061010323081406-pete@versatilecodingcom> (permalink)
References <8bb2eabb-fd3f-4355-9704-d430ce964f8d@m10g2000yqd.googlegroups.com>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Subject Re: std::set preallocate?
User-Agent Unison/2.1.4
Lines 34
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-4Zw1161rZ/Vy0cZ7FGK5cFjinrQ0DDZGJq+MP4Eq26UyZkkIHwhPFPc42BAcE9qNuUYBBvWprK39rHR!EphD5JPpAyUwVIkfFRnu/SXJV8KXyIh69/fbOPDKv6VO9iaBWrvo0tXdRWXeqnuy+ffFcvM=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2048
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:6585

Show key headers only | View raw


On 2011-06-10 10:01:02 -1000, Christopher said:

> Got a complaint that allocation is costly for 2000 items to be
> inserted into a set one by one. I need to preallocate, and depend on
> the set growing, if needed, after the number of items exceeds the
> preallocation.

Sets typically use a separate data block for each element, so 
allocating a bunch of blocks up front doesn't really accomplish 
anything. It's not like a vector, which uses a single data block and 
has to resize that block as elements are added.

> 
> Do I do so like this?

No, definitely not.

> 
> class A
> {
> public:
>    A()
>    {
>        m_values.get_allocator.allocate(2000);

This allocates a data block that can hold 2000 elements and throws away 
its address.

-- 
  Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The 
Standard C++ Library Extensions: a Tutorial and Reference 
(www.petebecker.com/tr1book)

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

std::set preallocate? Christopher <cpisz@austin.rr.com> - 2011-06-10 13:01 -0700
  Re: std::set preallocate? Pete Becker <pete@versatilecoding.com> - 2011-06-10 10:32 -1000
  Re: std::set preallocate? Edek <edek.pienkowski@gmail.com> - 2011-06-10 22:57 +0200
    Re: std::set preallocate? Christopher <cpisz@austin.rr.com> - 2011-06-10 14:51 -0700
      Re: std::set preallocate? Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2011-06-11 00:42 +0200
      Re: std::set preallocate? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-06-11 10:44 +0000
      Re: std::set preallocate? Edek <edek.pienkowski@gmail.com> - 2011-06-11 18:14 +0200
  Re: std::set preallocate? Juha Nieminen <nospam@thanks.invalid> - 2011-06-11 04:52 +0000

csiph-web