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


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

Re: initial size of a std::vector of std::strings

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.lang.c++
Subject Re: initial size of a std::vector of std::strings
Date 2022-12-07 18:45 +0100
Organization A noiseless patient Spider
Message-ID <tmqjfb$k0mf$1@dont-email.me> (permalink)
References (1 earlier) <6762abc6-85ac-4173-b807-aa27c36a04bcn@googlegroups.com> <tmplf6$3sr$1@gioia.aioe.org> <64dbcaba-4dc7-4aef-b1b1-11fd46f96a89n@googlegroups.com> <tmq8ej$ivl3$1@dont-email.me> <99fc9a54-2725-42fd-990a-2685bf55316fn@googlegroups.com>

Show all headers | View raw


Am 07.12.2022 um 18:33 schrieb Öö Tiib:

> Application programmer is in my experience rather capable of
> being unreasonable and micromanaging and reserving linearly.
> So when suggesting manual reserve() then it is always worth to
> warn that it is double edged sword not some kind of magic tool.

reserve isn't hard to use and it is used if you know the number
of inserted items. So I don't believe that a misuse of reserve()
is common.

> One example of common naive usage of reserve() is instead of
> plain insert() of range (that grows exponentially if needed) is
> checking how lot more storage is needed, reserving for it and
> then adding the elements. ...

That may sense if you have a really large vector that isn't backed
by a memory pool but allocated directly from the kernel and given
back to the kernel when being freed becaus of the size of the allo-
cation. If that happens the allocated pages aren't actually commit-
ted until you touch them and on some systems they're even not sub-
tracted from swap on allocation (overcommit).

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


Thread

initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-06 23:42 -0600
  Re: initial size of a std::vector of std::strings James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-12-07 00:52 -0500
  Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 08:17 +0100
  Re: initial size of a std::vector of std::strings Öö Tiib <ootiib@hot.ee> - 2022-12-07 00:23 -0800
    Re: initial size of a std::vector of std::strings Juha Nieminen <nospam@thanks.invalid> - 2022-12-07 09:13 +0000
      Re: initial size of a std::vector of std::strings Öö Tiib <ootiib@hot.ee> - 2022-12-07 06:03 -0800
        Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 15:37 +0100
          Re: initial size of a std::vector of std::strings Öö Tiib <ootiib@hot.ee> - 2022-12-07 09:33 -0800
            Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 18:45 +0100
      Re: initial size of a std::vector of std::strings Paavo Helde <eesnimi@osa.pri.ee> - 2022-12-07 16:34 +0200
        Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 15:38 +0100
        Re: initial size of a std::vector of std::strings Juha Nieminen <nospam@thanks.invalid> - 2022-12-08 07:58 +0000
    Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 16:28 -0600
      Re: initial size of a std::vector of std::strings Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 14:53 -0800
        Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 16:56 -0600
        Re: initial size of a std::vector of std::strings Juha Nieminen <nospam@thanks.invalid> - 2022-12-08 08:03 +0000
  Re: initial size of a std::vector of std::strings "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-07 12:28 +0100
    Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 14:54 -0600
      Re: initial size of a std::vector of std::strings "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-12-07 13:16 -0800
      Re: initial size of a std::vector of std::strings "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-07 22:33 +0100
        Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 22:37 +0100
      Re: initial size of a std::vector of std::strings Michael S <already5chosen@yahoo.com> - 2022-12-07 13:34 -0800
        Re: initial size of a std::vector of std::strings Bo Persson <bo@bo-persson.se> - 2022-12-07 23:48 +0100
      Re: initial size of a std::vector of std::strings Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 13:49 -0800
        Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 16:01 -0600
          Re: initial size of a std::vector of std::strings Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 14:47 -0800
            Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 17:09 -0600
      Re: initial size of a std::vector of std::strings Bo Persson <bo@bo-persson.se> - 2022-12-07 23:45 +0100
        Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 17:08 -0600
  Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-08 01:44 -0600

csiph-web