From: Martin Quinson Date: Sun, 10 Dec 2017 08:41:47 +0000 (+0100) Subject: simplification: no need for new/delete here X-Git-Tag: v3.18~58 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d3a0eace95a0fe3c152dc0376adde401d609a3ed simplification: no need for new/delete here --- diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp index 5ec1825408..f93c062440 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp @@ -13,38 +13,34 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(remote_io, "Messages specific for this io example") static int host(int argc, char* argv[]) { - simgrid::s4u::File* file = new simgrid::s4u::File(argv[1], nullptr); - const char* filename = file->getPath(); + simgrid::s4u::File file(argv[1], nullptr); + const char* filename = file.getPath(); XBT_INFO("Opened file '%s'", filename); - file->dump(); + file.dump(); - XBT_INFO("Try to read %llu from '%s'", file->size(), filename); - sg_size_t read = file->read(file->size()); - XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file->tell()); - XBT_INFO("Seek back to the begining of the stream..."); - file->seek(0, SEEK_SET); - XBT_INFO("Offset is now at: %llu", file->tell()); - - delete file; + XBT_INFO("Try to read %llu from '%s'", file.size(), filename); + sg_size_t read = file.read(file.size()); + XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file.tell()); + XBT_INFO("Seek back to the beginning of the stream..."); + file.seek(0, SEEK_SET); + XBT_INFO("Offset is now at: %llu", file.tell()); if (argc > 5) { - file = new simgrid::s4u::File(argv[2], nullptr); - filename = file->getPath(); + simgrid::s4u::File remoteFile(argv[2], nullptr); + filename = remoteFile.getPath(); XBT_INFO("Opened file '%s'", filename); - XBT_INFO("Try to write %llu MiB to '%s'", file->size() / 1024, filename); - sg_size_t write = file->write(file->size() * 1024); + XBT_INFO("Try to write %llu MiB to '%s'", remoteFile.size() / 1024, filename); + sg_size_t write = remoteFile.write(remoteFile.size() * 1024); XBT_INFO("Have written %llu bytes to '%s'.", write, filename); if (std::stoi(argv[5]) != 0) { - XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), + XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, remoteFile.size(), simgrid::s4u::Host::current()->getCname(), argv[3]); - file->remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]); - delete file; + remoteFile.remoteMove(simgrid::s4u::Host::by_name(argv[3]), argv[4]); } else { - XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file->size(), + XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, remoteFile.size(), simgrid::s4u::Host::current()->getCname(), argv[3]); - file->remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]); - delete file; + remoteFile.remoteCopy(simgrid::s4u::Host::by_name(argv[3]), argv[4]); } } @@ -58,22 +54,21 @@ int main(int argc, char** argv) e.loadPlatform(argv[1]); e.registerFunction("host", host); e.loadDeployment(argv[2]); - std::map* allStorages = new std::map; - simgrid::s4u::getStorageList(allStorages); + std::map allStorages; + simgrid::s4u::getStorageList(&allStorages); - for (auto const& s : *allStorages) { + for (auto const& s : allStorages) { XBT_INFO("Init: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA, sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname()); } e.run(); - for (auto const& s : *allStorages) { + for (auto const& s : allStorages) { XBT_INFO("End: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s.second) / INMEGA, sg_storage_get_size_free(s.second) / INMEGA, s.second->getCname()); } - delete allStorages; XBT_INFO("Simulation time %g", simgrid::s4u::Engine::getClock()); return 0; } diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.tesh b/examples/s4u/io-file-remote/s4u-io-file-remote.tesh index 7a69bc821a..803a1e011b 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.tesh +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.tesh @@ -40,18 +40,18 @@ $ ${bindir:=.}/s4u-io-file-remote$EXEEXT ${platfdir}/storage/remote_io.xml s4u-i > File Descriptor Id: 0 > [ 0.000000] (4@ dave) Try to read 67584 from 'c:\Windows\bootstat.dat' > [ 0.001469] (4@ dave) Have read 67584 from 'c:\Windows\bootstat.dat'. Offset is now at: 67584 -> [ 0.001469] (4@ dave) Seek back to the begining of the stream... +> [ 0.001469] (4@ dave) Seek back to the beginning of the stream... > [ 0.001469] (4@ dave) Offset is now at: 0 > [ 0.001469] (4@ dave) Opened file 'c:\Windows\Professional.xml' > [ 0.001469] (4@ dave) Try to write 31 MiB to 'c:\Windows\Professional.xml' > [ 0.003741] (1@alice) Have read 101663 from 'c:\Windows\setupact.log'. Offset is now at: 101663 -> [ 0.003741] (1@alice) Seek back to the begining of the stream... +> [ 0.003741] (1@alice) Seek back to the beginning of the stream... > [ 0.003741] (1@alice) Offset is now at: 0 > [ 0.276315] (3@ carl) Have read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'. Offset is now at: 12710497 -> [ 0.276315] (3@ carl) Seek back to the begining of the stream... +> [ 0.276315] (3@ carl) Seek back to the beginning of the stream... > [ 0.276315] (3@ carl) Offset is now at: 0 > [ 0.387036] (2@ bob) Have read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'. Offset is now at: 12710497 -> [ 0.387036] (2@ bob) Seek back to the begining of the stream... +> [ 0.387036] (2@ bob) Seek back to the beginning of the stream... > [ 0.387036] (2@ bob) Offset is now at: 0 > [ 0.387036] (2@ bob) Opened file '/scratch/doc/simgrid/examples/platforms/g5k.xml' > [ 0.387036] (2@ bob) Try to write 16 MiB to '/scratch/doc/simgrid/examples/platforms/g5k.xml'