No public description

PiperOrigin-RevId: 721786624
Change-Id: I8073f5dd09f050566eaa7e635acef1e04587692d
diff --git a/mpact/sim/util/memory/flat_demand_memory.cc b/mpact/sim/util/memory/flat_demand_memory.cc
index 216b51d..8107668 100644
--- a/mpact/sim/util/memory/flat_demand_memory.cc
+++ b/mpact/sim/util/memory/flat_demand_memory.cc
@@ -41,11 +41,7 @@
 }
 
 // Delete all the allocated blocks.
-FlatDemandMemory::~FlatDemandMemory() {
-  for (auto &[unused, block_ptr] : block_map_) {
-    delete[] block_ptr;
-  }
-}
+FlatDemandMemory::~FlatDemandMemory() { Clear(); }
 
 void FlatDemandMemory::Load(uint64_t address, DataBuffer *db, Instruction *inst,
                             ReferenceCount *context) {
@@ -183,6 +179,13 @@
   } while (size_in_units > 0);
 }
 
+void FlatDemandMemory::Clear() {
+  for (auto &[unused, block_ptr] : block_map_) {
+    delete[] block_ptr;
+  }
+  block_map_.clear();
+}
+
 }  // namespace util
 }  // namespace sim
 }  // namespace mpact
diff --git a/mpact/sim/util/memory/flat_demand_memory.h b/mpact/sim/util/memory/flat_demand_memory.h
index 4b34bdd..f583a2f 100644
--- a/mpact/sim/util/memory/flat_demand_memory.h
+++ b/mpact/sim/util/memory/flat_demand_memory.h
@@ -87,6 +87,9 @@
   }
   static constexpr int kAllocationSize = 16 * 1024;  // Power of two.
 
+  // Clears the memory and frees all allocated blocks.
+  void Clear();
+
  private:
   void LoadStoreHelper(uint64_t address, uint8_t *data_ptr, int size_in_units,
                        bool is_load);