0

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];
}
4
Contributors
3
Replies
27
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

0

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).

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.