C++ container question

P

Pat

I want to store objects into a C++ container (e.g. vector<object>,
deque<object>). Could someone help me the following questions.

1. Does there exist any size limit in the C++ container. For example, how
many objects can be stored in the vector<object>?

2. I want to store many thousand objects into a container, and use "find",
"sort" very often. Which standard container should be used in term of
efficiency and size limit?

Thanks.

Pat
 
D

Dave

Pat said:
I want to store objects into a C++ container (e.g. vector<object>,
deque<object>). Could someone help me the following questions.

1. Does there exist any size limit in the C++ container. For example, how
many objects can be stored in the vector<object>?

2. I want to store many thousand objects into a container, and use "find",
"sort" very often. Which standard container should be used in term of
efficiency and size limit?

Thanks.

Pat
1. Yes, no computer has infinite memory. It will be the lesser of the
value returned by vector::max_size() or what can fit in available memory.

2. From your description, it sounds as if std::set<> or std::map<> would be
best. They will stay sorted automatically and your finds will be
efficient - logarithmic time.
 
P

Pat

Thanks Dave.

Dave said:
1. Yes, no computer has infinite memory. It will be the lesser of the
value returned by vector::max_size() or what can fit in available memory.

2. From your description, it sounds as if std::set<> or std::map<> would be
best. They will stay sorted automatically and your finds will be
efficient - logarithmic time.
 
T

Thorsten Ottosen

|
| > I want to store objects into a C++ container (e.g. vector<object>,
| > deque<object>). Could someone help me the following questions.

| > 2. I want to store many thousand objects into a container, and use
"find",
| > "sort" very often. Which standard container should be used in term of
| > efficiency and size limit?

| 2. From your description, it sounds as if std::set<> or std::map<> would
be
| best. They will stay sorted automatically and your finds will be
| efficient - logarithmic time.

Depending on the object size, do consider
vector<Object> + sort() + binary_search()
for smaller objects.

br

Thorsten
 
S

Siemel Naran

Depending on the object size, do consider
vector<Object> + sort() + binary_search()
for smaller objects.

For large objects, vector<smart_ptr<Object>> could work too. (Of course,
this is same as vector<T> with T very small).
 
T

Thorsten Ottosen

| |
| > Depending on the object size, do consider
| > vector<Object> + sort() + binary_search()
| > for smaller objects.
|
| For large objects, vector<smart_ptr<Object>> could work too. (Of course,
| this is same as vector<T> with T very small).

not quite since there is an additional overhead by the smart pointers
control block and the indirection. If searching is
done many times and sorting is done eg 1 time, vector<object> will
outperform vector<smart_ptr<object> >.

br

Thorsten
 
M

Michiel Salters

Pat said:
Thanks Thorsten.

Is it possible to increase the "max_size"?

Pat

Usually, the maximum size of a vector is determined at runtime by the
available memory. and/or the number of bits in a pointer. Technically
it is controlled by something called an allocator, which can be replaced.
In practice, I don't know any implementation where max_size is easily
increased. The allocators AFAIK are limited by OS and CPU constraints.
I.e. they're good enough for the amount of memory present.

Regards,
Michiel Salters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top