Skip to content

Possible improvement to churn_allocator #46980

Open
@Dr15Jones

Description

@Dr15Jones

The churn_allocator

class churn_allocator : public std::allocator<T> {
causes memory coupling between modules which use the TrajectoryStateOnSurface class. This makes it difficult to look for memory issues within a module as memory allocation/deallocation spans across module boundaries.

A possible change could use a ChurnManager class which is put onto the stack and then the manager is passed to the churn_allocator's constructor. This would alleviate the need for a thread_local as the manager's lifetime would be limited to one thread. When the ChurnManager goes out of scope, it would make sure the cache is properly released if necessary (unlike now where the cache's pointer is never deleted). To avoid possible problems where the lifetime of the copied churn_allocator is longer than ChurnManger, the churn_allocator could hold a std::weak_pointer to the cache and if the cache is already gone the memory will just be deallocated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions