Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6585
| From | Pete Becker <pete@versatilecoding.com> |
|---|---|
| Organization | Roundhouse Consulting, Ltd. |
| Newsgroups | comp.lang.c++ |
| Date | 2011-06-10 10:32 -1000 |
| Message-ID | <2011061010323081406-pete@versatilecodingcom> (permalink) |
| References | <8bb2eabb-fd3f-4355-9704-d430ce964f8d@m10g2000yqd.googlegroups.com> |
| Subject | Re: std::set preallocate? |
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
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