From 5a49c5b9b12c305ed450a71ceb1a001585903a19 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 28 Apr 2020 19:17:47 +0200 Subject: [PATCH] Truncate the file used for the region mapping --- fairmq/shmem/Region.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fairmq/shmem/Region.cxx b/fairmq/shmem/Region.cxx index 4259fee4..1132bb94 100644 --- a/fairmq/shmem/Region.cxx +++ b/fairmq/shmem/Region.cxx @@ -19,6 +19,7 @@ #include #include +#include using namespace std; @@ -49,7 +50,17 @@ Region::Region(Manager& manager, uint64_t id, uint64_t size, bool remote, Region if (path != "") { fName = string(path + fName); - fFile = fopen(fName.c_str(), fRemote ? "r+" : "w+"); + if (!fRemote) { + // create a file + filebuf fbuf; + if (fbuf.open(fName, ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary)) { + // set the size + fbuf.pubseekoff(size - 1, ios_base::beg); + fbuf.sputc(0); + } + } + + fFile = fopen(fName.c_str(), "r+"); if (!fFile) { LOG(error) << "Failed to initialize file: " << fName;