On 06/30/2011 12:06 PM, WAROQUIERS Philippe wrote: >> Perhaps the best that you can do is modify the custom allocator >> using something like: >> ----- >> #include <valgrind.h> >> >> if (RUNNING_ON_VALGRIND) >> *p = 0; >> else if (*p) >> *p = 0; > > I wonder if the above "if-s" are really needed. > I think that on many modern cpu (with pipe lines etc), > it might be faster to just do > *p = 0; > return p; > > rather than to do one or more "if-s" to avoid an assignment.
Omitting the 'if's certainly is faster locally. However, the question is globally: if the lower-level allocator (lower than this one) returns mmap(,,,MAP_ANONYMOUS,,) then the unconditional store of 0 causes an immediate dirtying of a page (all MAP_ANONYMOUS pages initially refer to the _same_ single, zeroed physical page) with the associated overhead for operating system trap. (The original poster mentioned this in another reply.) If the end user of the page never writes to it otherwise (which happens more often than one might expect naively) then the immediate store here will waste thousands of cycles. If "production" code really does require the fewest local cycles, then suitable conditional compilation can turn "if (RUNNING_ON_VALGRIND)" into "if (0)", and a good compiler will optimize. If total software life cycle cost matters more, as usually it does, then having a "live" test for valgrind that can be activated instantly, even in deployed code at customer installations, is exceedingly valuable. Being able to diagnose a bug discovered by a customer, and fix it in one day instead of several, is worth a lot of real money. -- ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users