Big structures to be passed as values of STL map

N

naveen

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
 
S

SG

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top