J
jacek.dziedzic
Hi!
I need to be able to track memory usage in a medium-sized
application I'm developing. The only significant (memory-wise) non-
local objects are of two types -- std::vector<> and of a custom class
simple_vector<> that is a hand-rolled substitute for array<>. With the
latter I have code that tracks all allocations and destructions, so I
can account for all the memory.
The question is about std::vector<> -- how can I track memory usage
by individual std::vector's? I'm thinking along the lines of a wrapper
(templated) class, like std::tracked_vector<> which would have the
original std::vector<> as a private member, delegate relevant
operations to the underlying std::vector, while doing the accounting
job behind the scenes.
Are there any particular pitfalls to such a design? Would it suffice
to delegate only the methods I actually use,
like .size(), .reserve(), .at(), [] operators, etc. or would I need to
delegate all possible methods? I fear that since I use the
std::vector's in stl algorithms and other stl containers (vectors of
vectors), I might need to delegate all the iterator stuff and other
methods I don't use directly, is this the case? How do I account for
vectors of vectors, so that I don't bill the same memory twice?
Surely, someone must have gone that route, are there any particular
do's and don'ts there? Is it feasible? I don't want to reinvent the
wheel.
TIA,
- J.
I need to be able to track memory usage in a medium-sized
application I'm developing. The only significant (memory-wise) non-
local objects are of two types -- std::vector<> and of a custom class
simple_vector<> that is a hand-rolled substitute for array<>. With the
latter I have code that tracks all allocations and destructions, so I
can account for all the memory.
The question is about std::vector<> -- how can I track memory usage
by individual std::vector's? I'm thinking along the lines of a wrapper
(templated) class, like std::tracked_vector<> which would have the
original std::vector<> as a private member, delegate relevant
operations to the underlying std::vector, while doing the accounting
job behind the scenes.
Are there any particular pitfalls to such a design? Would it suffice
to delegate only the methods I actually use,
like .size(), .reserve(), .at(), [] operators, etc. or would I need to
delegate all possible methods? I fear that since I use the
std::vector's in stl algorithms and other stl containers (vectors of
vectors), I might need to delegate all the iterator stuff and other
methods I don't use directly, is this the case? How do I account for
vectors of vectors, so that I don't bill the same memory twice?
Surely, someone must have gone that route, are there any particular
do's and don'ts there? Is it feasible? I don't want to reinvent the
wheel.
TIA,
- J.