473,394 Members | 1,854 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,394 software developers and data experts.

std::container - preallocation size?

Hi,

can I tell e.g. a queue that it should re-allocate 512 elements each
time it comes to it's boundaries?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #1
5 2660
Gernot Frisch wrote:
can I tell e.g. a queue that it should re-allocate 512 elements each
time it comes to it's boundaries?


For some containers like std::vector() you could use the reserve()
function to implement this behavior yourself. As far as I know there is
no standard way to change the reallocation behaviour of containers.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 22 '05 #2
On Wed, 21 Jul 2004 12:04:30 +0200, "Gernot Frisch" <Me@Privacy.net>
wrote:
Hi,

can I tell e.g. a queue that it should re-allocate 512 elements each
time it comes to it's boundaries?


By default, queue uses std::deque as its storage. std::deque can't be
configured in how it behaves, but under VC++7.1 it is very time
efficient for queues since the segment map is implemented as a
circular buffer.

Tom
Jul 22 '05 #3

"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2m************@uni-berlin.de...
Hi,

can I tell e.g. a queue that it should re-allocate 512 elements each
time it comes to it's boundaries?


std::queue is just a wrapper around a STL sequence. It will have the same
reallocation strategy as the underlying sequence does.

If you want a particular reallocation strategy and none of the standard STL
sequences provide it, then you must code your own sequence that reallocates
in the way that you want, and then use that as a parameter to std::queue.

john
Jul 22 '05 #4
std::queue is just a wrapper around a STL sequence. It will have the same reallocation strategy as the underlying sequence does.

If you want a particular reallocation strategy and none of the standard STL sequences provide it, then you must code your own sequence that reallocates in the way that you want, and then use that as a parameter to

std::queue.

The second template argument? How would I do that? Can you give an
example?
Jul 22 '05 #5

"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2m************@uni-berlin.de...
std::queue is just a wrapper around a STL sequence. It will have the

same
reallocation strategy as the underlying sequence does.

If you want a particular reallocation strategy and none of the

standard STL
sequences provide it, then you must code your own sequence that

reallocates
in the way that you want, and then use that as a parameter to

std::queue.

The second template argument? How would I do that? Can you give an
example?


std::queue<int> my_queue; // std::deque is the default
std::queue<int, std::vector<int> > my_queue_2; // use std::vector instead
std::queue<int, MyContainer<int> > my_queue_3; // user defined class
instead

In each case std::queue is just a wrapper around another class, you can
specify which class by using the second template argument.

I forget exactly what methods MyContainer would have to have in order to be
successfully wrapped by std::queue, but it's the usual stuff, push_back,
pop_front, size, empty etc. etc. The point is that you can use whatever
reallocation strategy you like in MyContainer.

john
Jul 22 '05 #6

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

Similar topics

11
by: Vivi Orunitia | last post by:
Hi all, I tried looking this up in the sgi docs but it didn't provide any concrete answer to what I'm looking for. Basically, is there any difference between using ::iterator for a container vs...
20
by: Manuel | last post by:
Hi. Before all, please excuse me for bad english and for very newbie questions. I hope to don't boring you. I'm trying to write a very simple GUI using openGL. So I'm writing some different...
9
by: Gernot Frisch | last post by:
Hi, I want to be able to write: class foo { std::vector<intm_i (64); }
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.