Re: Memory issues with Map
mohitanchlia@gmail.com wrote:
I have written a program that loads a file having 3 columns into a
map. Here is the declaration:
struct strE
{
char iEID[22+1];
char acEN[6+1];
int iDed;
};
map<string, struct strE> mEro;
You may omit the keyword 'struct' here. It's not needed. 'strE'
is the name of the *type* (just like 'string'). We're not in C any
more.
struct strE eStr = {0,};
Same here, you may omit 'struct '.
if ( 0 < vDataColumn.size() )
eStr.iDzReceived =
There is no member 'iDzReceived' in 'strE'.
atol(vDataColumn.at(0).c_str());
//vDataColumn has columns from file which is "|" delimiter separated.
We split the line into columns and store it in vDataColumn
mEro.insert(std::pair<std::string,
struct strERO>(key, eStr)
What's 'strERO'?
);
I am seeing that for 6MB file the resident memory is around 12 MB. It
looks like either there is a memory leak or limitation in Map.
Memory leak can be discovered by using the tools that exist for that
particular purpose. Limitation in std::map? Looks a lot more like
"overhead" than "limitation" to me...
I am
not sure what kind of memory mangement is used by Map. Could somebody
shed some light as what would be the best approach and dos and donts
when dealing with Maps
Please find a copy of 'The C++ Standard Library' by Josuttis. It
contains so much information on memory allocation for standard
containers that the margins of this posting are too narrow to hold
it.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask