Big structures to be passed as values of STL map

Discussion in 'C++' started by naveen, Nov 24, 2010.

  1. naveen

    naveen Guest

    All,
    I want to use a map whose key is an int and value is a big structure
    (500 bytes). Which one is better approch

    1. passing value as it is map<key,struct>

    2. passing value by address map<key,struct*)

    I was thinking in first case, since whole structure is passed when new
    stack frames are created (ELF format) for STL functions, whole
    structure will be passed to the stack (this is infact true for any
    function)

    Moreover in first case all memory allocation will be done by STL
    allocator (assume default allocator), in second case I can allocate
    memory from my memory manager ( I do no have custom STL allocator)

    Please let me know the pros and cons of both the approaches.
    thanks
    Naveen
     
    naveen, Nov 24, 2010
    #1
    1. Advertising

  2. naveen

    SG Guest

    On 24 Nov., 08:08, naveen wrote:
    > All,
    > I want to use a map whose key is an int and value is a big structure
    > (500 bytes). Which one is better approch
    >
    > 1. passing value as it is map<key,struct>
    >
    > 2. passing value by address map<key,struct*>


    Test it. If the structure is a POD, I wouldn't mind copying it around
    -- even if its size is 500 bytes -- if that means I don't need to
    worry about when and where they are allocated and deleted. And if the
    structure is not a POD it still might be worth copying.

    > Please let me know the pros and cons of both the approaches.


    You're smart. You'll figure it out.

    Cheers!
    SG
     
    SG, Nov 24, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alfonso Morra
    Replies:
    11
    Views:
    722
    Emmanuel Delahaye
    Sep 24, 2005
  2. Shaguf
    Replies:
    0
    Views:
    363
    Shaguf
    Dec 24, 2008
  3. Shaguf
    Replies:
    0
    Views:
    459
    Shaguf
    Dec 26, 2008
  4. Shaguf
    Replies:
    0
    Views:
    245
    Shaguf
    Dec 26, 2008
  5. Shaguf
    Replies:
    0
    Views:
    221
    Shaguf
    Dec 24, 2008
Loading...

Share This Page