Re: Memory issues with Map
mohitanchlia@gmail.com wrote:
Here is how data looks like
1234567891234567891.1000|2
Could the firstKey ever be as long as 22 chars? Could the second key
ever be as long as 6?
So the syntax of the file is "firstkey.secondkey|remaining fields"
Remaining fields? You've only shown one. What could the others be? Is
there only ever one?
strE is struct for the format that I just mentioned.
I'm still struggling to understand. Do you mean that you essentially do
this:
Note it's just a snippet and it's not tested and it won't work well.
struct strE {
char iEID[22+1];
char acEN[6+1];
int iDed;
strE(const char *p1, const char *p2, const int i) {
strcpy(iEID,p1);
strcpy(acEN,p2);
iDed = i;
}
};
std::map<std::string, strE> m;
and then for each data record in your file
const std::string firstKey = extractFirstKeyFromRecord();
const std::string secondKey = extractSecondKeyFromRecord();
const int i = extractIntFromRecord();
m[firstKey+secondKey] = strE(firstKey.c_str(), secondKey.c_str(), i);
Is that what you're doing?
If that's it, then you can save plenty of memory at the price of a
little time and space overhead, by removing the two char fields from
your struct and creating a wrapper for the key from the two extracted
strings from the data. I estimate the data space overhead at something
like 24 more bytes per entry but you'd save 30 from the struct for a
savings of 6 bytes per entry. Around 1.2M. Use a lightweight string
class and it gets a little bit better. Or you can make a struct for the
key that uses char arrays to store the data and do even better.
But I'm still not sure what you're doing with the data that you read in,
or what data ends up in strE.
I'm missing something.
LR