Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Big structures to be passed as values of STL map

Reply
Thread Tools

Big structures to be passed as values of STL map

 
 
naveen
Guest
Posts: n/a
 
      11-24-2010
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
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      11-24-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net 0 12-26-2008 09:29 AM
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net Web Controls 0 12-26-2008 06:11 AM
GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf Python 0 12-24-2008 07:35 AM
GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf Ruby 0 12-24-2008 05:07 AM
structures, structures and more structures (questions about nestedstructures) Alfonso Morra C Programming 11 09-24-2005 07:42 PM



Advertisments