Sparta Share pointer Allocator Warning/Error #445
-
When I use non static Sparta share ptr allocator to allocate object sent on non-zero delay port, simulator throws warning/error at end of the simulation.
After debugging a bit found that DataContainer on port retains the object until its reassigned by next object sent on the port ( For now I am using static sparta allocator. But would be good to know if it's expected to use static allocator by design or this is something that needs to be fixed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You are correct. If you use an allocator, it must outlive all containers/objects in your simulation that pull from it. This is actually documented in the Allocator class doxygen (about the third paragraph down in the Detailed Description). One idea that I've seen is that modelers will create a
Keep in mind that this is mostly how all allocator objects work. Mine is just more "complainy" to help you find bugs. 😉 |
Beta Was this translation helpful? Give feedback.
-
Ironically, this issue just popped up in Olympia. Here's the PR that fixes it: riscv-software-src/riscv-perf-model#97 |
Beta Was this translation helpful? Give feedback.
You are correct. If you use an allocator, it must outlive all containers/objects in your simulation that pull from it. This is actually documented in the Allocator class doxygen (about the third paragraph down in the Detailed Description).
One idea that I've seen is that modelers will create a
sparta::TreeNode
in their simulation class that contains all of the allocators used in simulation. This TreeNode is created and attached to root (getRoot()
) during BuildTree phase and is "looked for" bysparta::Unit
types during construction. This allocator container class is torn down automatically when the Simulation class is destroyed (which means it's the last object alive).