C++ container question | | |
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 | | | | re: C++ container question
"Pat" <Pat@Pat.com> wrote in message news:4083ffbd$1_3@rain.i-cable.com...[color=blue]
> 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
>
>[/color]
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. | | | | re: C++ container question
Thanks Dave.
"Dave" <better_cs_now@yahoo.com> 在郵件
news:10880hssq806r3b@news.supernews.com 中撰寫...[color=blue]
>
> "Pat" <Pat@Pat.com> wrote in message news:4083ffbd$1_3@rain.i-cable.com...[color=green]
> > 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,[/color][/color]
how[color=blue][color=green]
> > many objects can be stored in the vector<object>?
> >
> > 2. I want to store many thousand objects into a container, and use[/color][/color]
"find",[color=blue][color=green]
> > "sort" very often. Which standard container should be used in term of
> > efficiency and size limit?
> >
> > Thanks.
> >
> > Pat
> >
> >[/color]
> 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[/color]
be[color=blue]
> best. They will stay sorted automatically and your finds will be
> efficient - logarithmic time.
>
>[/color] | | | | re: C++ container question
|
| "Pat" <Pat@Pat.com> wrote in message news:4083ffbd$1_3@rain.i-cable.com...
| > 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 | | | | re: C++ container question
"Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message
news:40847e80$0$25655
[color=blue]
> Depending on the object size, do consider
> vector<Object> + sort() + binary_search()
> for smaller objects.[/color]
For large objects, vector<smart_ptr<Object>> could work too. (Of course,
this is same as vector<T> with T very small). | | | | re: C++ container question
"Siemel Naran" <SiemelNaran@REMOVE.att.net> wrote in message
news:z_0hc.1555$_o3.43361@bgtnsc05-news.ops.worldnet.att.net...
| "Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message
| news:40847e80$0$25655
|
| > 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 | | | | re: C++ container question
Thanks Thorsten.
Is it possible to increase the "max_size"?
Pat
"Thorsten Ottosen" <nesotto@cs.auc.dk> 在郵件
news:40847e80$0$25655$afc38c87@news.optusnet.com.a u 中撰寫...[color=blue]
> |
> | "Pat" <Pat@Pat.com> wrote in message[/color]
news:4083ffbd$1_3@rain.i-cable.com...[color=blue]
> | > 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<>[/color]
would[color=blue]
> 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
>
>[/color] | | | | re: C++ container question
"Pat" <Pat@Pat.com> wrote in message news:<408492e2$1_2@rain.i-cable.com>...[color=blue]
> Thanks Thorsten.
>
> Is it possible to increase the "max_size"?
>
> Pat[/color]
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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|