Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Pre-Allocating stl maps / multimaps

Pre-Allocating stl maps / multimaps

Scheduled Pinned Locked Moved ATL / WTL / STL
c++question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jabin Reinhold
    wrote on last edited by
    #1

    Has anybody figured out a way to preallocate a multimap?

    G J 3 Replies Last reply
    0
    • J Jabin Reinhold

      Has anybody figured out a way to preallocate a multimap?

      G Offline
      G Offline
      gokings
      wrote on last edited by
      #2

      Do you mean to allocate it at compile time? Or do you mean that you know how many entries you will add, and you want to reserve the memory ahead of time? If the former, I don't believe it can be done. If the latter, I would suggest making the values pointers, e.g., map. You could potentially preallocate the memory for CFoos (simple if it is just a struct, otherwise more work). The memory for the nodes would not be preallocated, but the nodes would be fairly small.

      1 Reply Last reply
      0
      • J Jabin Reinhold

        Has anybody figured out a way to preallocate a multimap?

        G Offline
        G Offline
        gokings
        wrote on last edited by
        #3

        Well, I was unaware of the following article when I replied earlier. You may be well aware of it. It applies to maps, but I don't know whether multimaps are supported, I have not spent the time to check. For what it is worth: http://www.codeproject.com/vcpp/stl/PGIL.asp

        1 Reply Last reply
        0
        • J Jabin Reinhold

          Has anybody figured out a way to preallocate a multimap?

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          I think you'd have to hook in your own allocator for that. The std::[multi]maps are implemented as red/black binary trees IIRC, so they are very dynamic in structure, just like a linked list. Hence you don't see a reserve() method in their interfaces. hashmaps are by definition preallocated, but I'm not sure if hashmaps are part of STL yet. -- Denn du bist, was du isst! Und ihr wisst, was es ist! Es ist mein Teil...?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups