Solved

Static allocation of the stl map size

Posted on 2001-07-03
4
474 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

770 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