Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use std::vector for Process::heap_info
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 2 Nov 2015 10:23:47 +0000 (11:23 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 2 Nov 2015 10:23:47 +0000 (11:23 +0100)
src/mc/Process.cpp
src/mc/Process.hpp

index 125c722..ea58d75 100644 (file)
@@ -216,7 +216,6 @@ Process::Process(pid_t pid, int sockfd) : AddressSpace(this)
   process->status_ = 0;
   process->memory_map_ = get_memory_map(pid);
   process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
-  process->heap_info = NULL;
   process->init_memory_map_info();
   process->clear_refs_fd_ = -1;
   process->pagemap_fd_ = -1;
@@ -274,9 +273,6 @@ Process::~Process()
 
   process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
 
-  free(process->heap_info);
-  process->heap_info = NULL;
-
   if (process->clear_refs_fd_ >= 0)
     close(process->clear_refs_fd_);
   if (process->pagemap_fd_ >= 0)
@@ -310,10 +306,10 @@ void Process::refresh_malloc_info()
   if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
     this->refresh_heap();
   // Refresh process->heapinfo:
-  size_t malloc_info_bytesize =
-    (this->heap->heaplimit + 1) * sizeof(malloc_info);
-  this->heap_info = (malloc_info*) realloc(this->heap_info, malloc_info_bytesize);
-  this->read_bytes(this->heap_info, malloc_info_bytesize,
+  size_t count = this->heap->heaplimit + 1;
+  if (this->heap_info.size() < count)
+    this->heap_info.resize(count);
+  this->read_bytes(this->heap_info.data(), count * sizeof(malloc_info),
     remote(this->heap->heapinfo), simgrid::mc::ProcessIndexDisabled);
   this->cache_flags |= MC_PROCESS_CACHE_FLAG_MALLOC_INFO;
 }
index f6b941a..223711a 100644 (file)
@@ -100,7 +100,7 @@ public:
   {
     if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
       this->refresh_malloc_info();
-    return this->heap_info;
+    return this->heap_info.data();
   }
 
   std::vector<IgnoredRegion> const& ignored_regions() const
@@ -208,7 +208,7 @@ public: // Copies of MCed SMX data structures
    *  This is not used if the process is the current one:
    *  use `get_malloc_info()` in order to use it.
    */
-  malloc_info* heap_info;
+  std::vector<malloc_info> heap_info;
 
 public: // Libunwind-data