Hey guys...so for my homework i have to do this...would it be possible if someone helped me with this? Not very familiar with maps and stuff like that yet...thx a lot! So here's the question:

Suppose there is an application that allows users to enter a phone number to search for a name. After running the application for a long time, it is found that the application used up a lot of memory. It is known that the phone book is defined as a map in the program:

map<int, string> phonebook;

And the lookup function is implemented as follow:

string lookup(int phone) {
    return phonebook[phone];
}

Recommended Answers

All 3 Replies

There's nothing in those snippets that would make me suspect the map as cause for a memory leak. If the map itself is confirmed to be using "lots" of memory, my first question would be how many phone numbers are stored, and are all of them validated to actually be phone numbers?

It could be perfectly normal behavior if you have oodles of phone numbers.

Can you even post your code and error? Show some relationship with your claim ok?.

Instead of trying to blaim memory leaks on your compiler you should be looking at your own code for them. Most compilers have been tested pretty thoroughly. In 25+ years coding I think I found just ONE compiler-generated memory leak (in malloc/free functions, and that was over 10 years ago, and that was caused by memory fragmentation).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.