Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::vector reserve

Reply
Thread Tools

std::vector reserve

 
 
john
Guest
Posts: n/a
 
      03-21-2011
Hi,

If I use std::vector's reserve on a newly created vector, is the amount
of memory reserved equal to the requested amount or at least equal to
the requested amount. In other words, if I have


std::vector<int> a;
a.reserve(10);

I know that 'a' will have memory for at least 10 int's. Can I be
certain that the amount of memory is for exactly 10 int's?

Thanks,
John
 
Reply With Quote
 
 
 
 
john
Guest
Posts: n/a
 
      03-21-2011
> From n3242:
>
> "void reserve(size_type n);
> 2 Effects: A directive that informs a vector of a planned change in
> size, so that it can manage the storage
> allocation accordingly. After reserve(), capacity() is greater or equal
> to the argument of reserve if
> reallocation happens; and equal to the previous value of capacity()
> otherwise. Reallocation happens
> at this point if and only if the current capacity is less than the
> argument of reserve(). If an exception
> is thrown other than by the move constructor of a non-CopyInsertable
> type, there are no effects."
>
> So I guess the answer is that capacity will be *at least* 10 in your
> example.


Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CASTE.BIZ one-word Indian domain eBay No Reserve Price dot HTML 0 11-28-2005 05:00 AM
reserve bandwith for certain ips jcharth@hotmail.com Cisco 4 03-06-2005 06:57 PM
XML 2004 just 3 weeks away -- view program updates -- reserve room -- register today MarionEll XML 0 10-26-2004 01:47 PM
FA: O'Reilly Java Enterprise CD Bookshelf and book (bidding starts at $1.00 with NO RESERVE) J.W. Java 0 04-19-2004 09:40 PM
How to reserve white space for a particular element in XSLT joeblack XML 3 11-04-2003 02:07 AM



Advertisments