> >> Sorry for the late reply.
> >>
[quoted text clipped - 32 lines]
>
> -cd
>> char*'s, the list isn't managing the memory occupied by the strings
>> - you are.
[quoted text clipped - 10 lines]
> {
> filename = new char [500];
This memory is being leaked when you remove an item from the list - nothing
will call delete[] on it (unless there's yet more code that you haven't
shown that does delete it).
> strcpy ( filename , finddata.cFileName );
> filenames.push_back ( filename );
[quoted text clipped - 3 lines]
> } while ( FindNextFileA( filehandle, & finddata ) != 0 );
> FindClose ( filehandle );
I'd recommend changing your container to std::list<std::string>, then the
memory for the string will be automatically freed when an item is removed
from the list.
-cd
Abubakar - 17 Aug 2006 08:15 GMT
> I'd recommend changing your container to std::list<std::string>, then the
> memory for the string will be automatically freed when an item is removed
yes I was going to write the code for the deletion of char *, but I got
stuck in that filenames.end() condition which btw is still not working. This
std::string idea is good and will reduce my code.
-Ab.
> >> char*'s, the list isn't managing the memory occupied by the strings
> >> - you are.
[quoted text clipped - 28 lines]
>
> -cd
Tamas Demjen - 17 Aug 2006 18:33 GMT
> yes I was going to write the code for the deletion of char *, but I got
> stuck in that filenames.end() condition which btw is still not working.
Have you tried what Bo and Carl recommended? Here's a complete example:
for(std::list<std::string>::iterator filename = filenames.begin();
filename != filenames.end(); )
{
if(FileNeedsToBeDeletedCondition)
filename = filenames.erase(filename);
else
++filename;
}
If have a radically different mechanism, it's probably not going to work.
I strongly recommend the book Effective STL by Scott Meyers, which
discusses this and dozens of other tricks with STL containers.
Tom
Abubakar - 19 Aug 2006 17:04 GMT
Hi,
I have solved the problem by using the list::back() method. As back()
represents the last item in the list, so thats what I was looking for. The
problem with what I was doing was my lack of understanding with the list's
"end" method. I thought that the "end" represents the last item, which is
not correct.
Thanks for the book recommendation!
Regards,
-Ab.
PS: again, sorry for having replied so late,,,, I hate my replying-late
habbit !!!
> > yes I was going to write the code for the deletion of char *, but I got
> > stuck in that filenames.end() condition which btw is still not working.
[quoted text clipped - 16 lines]
>
> Tom