@@ -174,6 +174,62 @@ class TryAllocVisitor : public AllocatorVisitor {
174174 const std::vector<size_t >& sizes_;
175175 bool is_try_alloc_success_ = false ;
176176};
177+
178+ /* *
179+ * @brief Visitor class to retrieve free block information from a VMM allocator.
180+ *
181+ * Inherits from AllocatorVisitor, implementing the Visitor Pattern.
182+ * The purpose of this class is to access a specific memory allocator's
183+ * internal state (the list of free memory blocks) and extract key information
184+ * (size and address) for external analysis or debugging.
185+ */
186+ class VMMFreeBlocksInfoVisitor : public AllocatorVisitor {
187+ public:
188+ /* *
189+ * @brief Default Constructor.
190+ */
191+ VMMFreeBlocksInfoVisitor () {}
192+
193+ /* *
194+ * @brief Retrieves the collected information about the free memory blocks.
195+ *
196+ * The structure is a nested vector:
197+ * Outer Vector: Represents different categories or lists within the
198+ * allocator. Inner Vector: Contains pairs of (size, address) for the free
199+ * blocks in that category. uintptr_t is used to safely store the memory
200+ * address (void*) as an integer.
201+ *
202+ * @return A nested vector structure containing the size and integer address
203+ * of all free blocks.
204+ */
205+ std::vector<std::vector<std::pair<size_t , uintptr_t >>> GetFreeBlocksInfo ()
206+ const {
207+ return free_blocks_info_;
208+ }
209+
210+ /* *
211+ * @brief Visits the VirtualMemoryAutoGrowthBestFitAllocator.
212+ *
213+ * This is the core implementation of the Visitor Pattern. When called,
214+ * it accesses the `allocator` object's internal structure that holds the
215+ * free block list(s) and populates the `free_blocks_info_` member variable
216+ * with the necessary data.
217+ *
218+ * @param allocator Pointer to the memory allocator object whose free blocks
219+ * information is to be extracted.
220+ */
221+ void Visit (VirtualMemoryAutoGrowthBestFitAllocator* allocator) override ;
222+
223+ private:
224+ /* *
225+ * @brief Stores the extracted free block information.
226+ *
227+ * This member is populated during the Visit() call. It is structured to
228+ * hold lists of (size, address) pairs, where the outer vector typically
229+ * distinguishes between different free lists (e.g., small, large blocks).
230+ */
231+ std::vector<std::vector<std::pair<size_t , uintptr_t >>> free_blocks_info_;
232+ };
177233#endif
178234
179235} // namespace memory
0 commit comments