Skip to content

Sparta Share pointer Allocator Warning/Error #445

Answered by ghost
rahul-neubla asked this question in Q&A
Discussion options

You must be logged in to vote

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" by sparta::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).

class MySimAllocator…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@rahul-neubla
Comment options

@ghost
Comment options

Answer selected by rahul-neubla
Comment options

You must be logged in to vote
2 replies
@rahul-neubla
Comment options

@ghost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant