Can G4Allocator objects have std::vector data members?

I have a custom hit class with an associated G4Allocator. The documentation is clear that such an object must have a “constant size”:

G4Allocator assumes that objects being allocated have all the same size for the type they represent. For this reason, classes which are handled by G4Allocator should avoid to be used as base-classes for others.

How does this assumption apply to objects containing a std::vector? My understanding is that the std::vector object is fixed size; it contains a pointer to the underlying array of entities in the vector, and that array may be freed and reallocated somewhere else as the vector grows.

Is this an issue when using G4Allocator? Should I instead use C-style arrays with a pre-set “MAXENTRIES” dimension and “nEntries” data member?

Your understanding is right. A std::vector uses its own internal allocator for handling the storage of its elements. This should not affect for any means the size of your object handled by G4Allocator.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.