mercredi 29 juillet 2015

How can a unit test prove whether VirtualAlloc was called?

I'm writing a unit test for a (Win7) C++ routine that is being optimized, which formerly freed and re-allocated a lot of giant buffers: memory churn. I would like to prove that during the unit test, the program doesn't allocate any large memory regions (say 16M or larger) but instead efficiently re-uses its memory that was allocated at initialization time. It comes down to that the unit test should fail if VirtualAlloc has been called to get some large region (say 16M).

Is there an elegant way to count stats on Windows VirtualAlloc calls that have executed under a unit test? This would become part of the automatic regression test suite, so using an external tool is not feasible.

Checking the total memory committed is not a good fit, because I want to assert that the routine is no longer churning (freeing and re-allocating buffers.)

Aucun commentaire:

Enregistrer un commentaire