Solved

Static allocation of the stl map size

Posted on 2001-07-03
4
478 Views
Last Modified: 2013-12-14
Hi,
I heard that it is possible to allocate the size of the stl map in the static way.(something like reserve(n) in the stl vector).
Do you know how?
Thanks,
Inna
0
Comment
Question by:innab
  • 3
4 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 6248806
No.  That sort of function does not make sense for a map--or for a list for that matter.   For a vector, you can use that function to "preallocate" the storage space for the data.  That is helpfull since the vector stores all the data in a single block.  But a map is (usualy) a tree structure and this each item is stored in its own block, so there would be no advantage to knowing the final size ahead of time.
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 6248822
That is sort of confussing isn't it.  Let me try that again.

For a vector the data is stored in a single block, then that block is not large enough, an new block needs to be created and the data copied to the new block.  Thius reserve and capacity make sense for that type of container.   Buf for a container like map or list, there is never a need to perform a large allocation and copy like in vector.  The reason is that map and list store each item in their own block, not a single block, so there to concept of having extra room to expand into doesn't make sense.  
0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 6249079
You could come close to what you want by defining a custom allocator and using some sort of memory pool for the map elements.

This is probably not a task to be undertaken lightly, however.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6249185
Its also not likely to cause the type of speed increase that the reserve operation does--nor is that sort of speed increase really really needed, it is a major limitation to addition in vector, map doesn't suffer it.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question