memory management with glibmm & giomm
- From: nico <nico yojik eu>
- To: gtkmm-list gnome org
- Subject: memory management with glibmm & giomm
- Date: Wed, 08 Oct 2008 17:15:53 +0200
Hi everybody,
Here is a program that list recursively files from a given directory.
As I understood, Glib unref() my 3 variables at the end of the bloc {},
so I don't have to care about that.
But when It run this program, after 2 minutes it use already more than
80 MB. Is something wrong?
My second question is about the "enumerator->close();" command. Is this
line mendatory? (It doesn't seems to change anything).
Regards,
Nicolas
#include <iostream>
#include <glibmm.h>
#include <giomm.h>
bool scan_directory(std::string path) {
try {
Glib::RefPtr<Gio::File> directory =
Gio::File::create_for_path(path);
Glib::RefPtr<Gio::FileEnumerator> enumerator =
directory->enumerate_children();
Glib::RefPtr<Gio::FileInfo> file_info;
while (file_info = enumerator->next_file()) {
if (file_info->get_file_type() == Gio::FILE_TYPE_DIRECTORY)
scan_directory(path + file_info->get_name() +
G_DIR_SEPARATOR_S);
else {
//do some staff, for example:
std::cout << path + file_info->get_name() << "\t" <<
file_info->get_content_type() << std::endl;
}
}
enumerator->close(); //seems to be not necessary
return true;
}
catch(const Glib::Exception& ex) {
std::cerr << "Error: " << ex.what() << std::endl;
return false;
}
}
int main(int argc, char** argv) {
setlocale(LC_ALL, "");
Glib::init();
Gio::init();
scan_directory((argc == 2) ? argv[1] : "");
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]