473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

# of elements in vector

Hi,

is there a general limit for the number of elements that can be stored
in a vector or is it implementation specific?

Thanks,

Ralf
Sep 18 '06 #1
9 1719
Ralf Goertz <r_******@expires-2006-10-31.arcornews.dewrote:
is there a general limit for the number of elements that can be stored
in a vector or is it implementation specific?
Yes and yes. The limit is defined by vector::max_size().

--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 18 '06 #2
Daniel T. wrote:
Ralf Goertz <r_******@expires-2006-10-31.arcornews.dewrote:
>is there a general limit for the number of elements that can be stored
in a vector or is it implementation specific?

Yes and yes. The limit is defined by vector::max_size().
Well, sort of. max_size gives you a value that might succeed, but there
are many other things that affect the actual number of elements that you
can store, the most important being available memory. In fact, max_size
is basically useless.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Sep 18 '06 #3
Pete Becker <pe********@acm.orgwrote:
Daniel T. wrote:
Ralf Goertz <r_******@expires-2006-10-31.arcornews.dewrote:
is there a general limit for the number of elements that can be stored
in a vector or is it implementation specific?
Yes and yes. The limit is defined by vector::max_size().

Well, sort of. max_size gives you a value that might succeed, but there
are many other things that affect the actual number of elements that you
can store, the most important being available memory.
I was incomplete in my answer... max_size() defines the upper limit, the
actual limit, as you say, may be lower.
In fact, max_size is basically useless.
It's useless only in that it is usually so large that the likelihood of
trying to allocate memory larger than it is extremely rare. As I
understand it though, sending a value to resize() that is greater than
max_size() is undefined isn't it? If so, then it has some use. :-)

--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 18 '06 #4
Daniel T. wrote:
Pete Becker <pe********@acm.orgwrote:
>In fact, max_size is basically useless.

It's useless only in that it is usually so large that the likelihood of
trying to allocate memory larger than it is extremely rare. As I
understand it though, sending a value to resize() that is greater than
max_size() is undefined isn't it? If so, then it has some use. :-)
I don't think so. vector::resize is defined as a call to insert, and
insert "causes reallocation if the new size is greater than the old
capacity." At that point, if memory isn't available for whatever reason,
you get bad_alloc. It's certainly possible to implement that
reallocation badly so that you get erroneous results when the new size
is larger than max_size, but I don't see that that's allowed.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Sep 18 '06 #5

"Pete Becker" <pe********@acm.orgwrote in message
news:qJ******************************@giganews.com ...
Daniel T. wrote:
>Ralf Goertz <r_******@expires-2006-10-31.arcornews.dewrote:
>>is there a general limit for the number of elements that can be stored
in a vector or is it implementation specific?

Yes and yes. The limit is defined by vector::max_size().

Well, sort of. max_size gives you a value that might succeed, but there
are many other things that affect the actual number of elements that you
can store, the most important being available memory. In fact, max_size is
basically useless.
Except that given unlimited memory, and an element of size 1, you
can't have more than the maximum value held in size_t.
Sep 18 '06 #6
In article <Ik********************@weber.videotron.net>,
"Duane Hebert" <sp**@flarn2.comwrote:
"Pete Becker" <pe********@acm.orgwrote in message
news:qJ******************************@giganews.com ...
Daniel T. wrote:
Ralf Goertz <r_******@expires-2006-10-31.arcornews.dewrote:

is there a general limit for the number of elements that can be stored
in a vector or is it implementation specific?

Yes and yes. The limit is defined by vector::max_size().
Well, sort of. max_size gives you a value that might succeed, but there
are many other things that affect the actual number of elements that you
can store, the most important being available memory. In fact, max_size is
basically useless.

Except that given unlimited memory, and an element of size 1, you
can't have more than the maximum value held in size_t.
Which is what max_size would return.

--
There are two things that simply cannot be doubted. Logic and our
ability to sense the world around us. Doubt those, and you no longer
have anyone to discuss it with, nor any ability to discuss it.
Sep 19 '06 #7
Duane Hebert wrote:
>
Except that given unlimited memory,
I've never had the opportunity to use a system with unlimited memory.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Sep 19 '06 #8
Pete Becker wrote:
Well, sort of. max_size gives you a value that might succeed, but there
are many other things that affect the actual number of elements that you
can store, the most important being available memory. In fact, max_size
is basically useless.
Well, I "fondly" remember an implementation, that had a
list::max_size() of 32267. This really did pose serious practical
problems for large lists of triangles in isosurfaces for the programs I
worked with.

I don't remember any more if I could get away with switchching to
vector (which probably would have been the smarter approach from the
start) or if I had to go back to malloc and trusty old C. Ah, the fun
days of VC6 ;-)

Sep 19 '06 #9

"Pete Becker" <pe********@acm.orgwrote in message
news:v4******************************@giganews.com ...
Duane Hebert wrote:
>>
Except that given unlimited memory,

I've never had the opportunity to use a system with unlimited memory.
No. My reply was mostly "tongue in cheek" but the
OP was asking about any restrictions of the max elements
by the standard. AFAIK, the only one would be size_t
(or as Daniel says max_size.)

In practice however...
Sep 19 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
6
by: Jason Heyes | last post by:
What is a good way of removing elements from std::vector so that the elements removed satisfy a predicate and end up stored in another std::vector. It seems as though the algorithm std::remove_if...
6
by: Matthias | last post by:
Hi, say I have a vector v1: std::vector<SomeType> v1; and I need a vector v2 of pointers to v1's elements: std::vector<SomeType*> v2;
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
11
by: koperenkogel | last post by:
Dear cpp-ians, I am working with a vector of structures. vector <meta_segment> meta_segm (2421500); and the structure look like: struct meta_segment { float id; float num;
9
by: david wolf | last post by:
I want to delete all even numbers in a vector, I am not sure if there's any better way to do it. Following program is how I did it. Look at the part of code beginning from comments: //delete all...
8
by: cayblood | last post by:
Hello, I have been interested in something kind of like the next_permutation from the STL algorithm library, except that I want it to find possible combinations of vector elements. Here is a more...
4
by: Christian Bruckhoff | last post by:
Hi. Is there a possibility to delete elements out of a vector? At the moment i do it by copying all needed elements to another vector. After clearing the old vector i copy them back element by...
1
by: Alan | last post by:
I am wondering if anyone has any better idea of how to approach this problem than I do. . . . I have a vector of items (data). I have to do a pairwise comparison of each item to each other item...
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.