Posted February 19, 201213 yr hi,i am writing a function in c++ (msvc2008 pro), which has to be "portable" (ie. no calls to other functions or APIs) and fast.At one point i am using something like while(tlen++ < total) *str++ = leChar;which works fine, but msvc choses to "optimize" it to a crt-memset call. :/I generally noticed msvc is very keen on replacing code with crt calls to memset, even my custom memset-function, which uses an inlined REPMOV (and serves the sole purpose of making me independant from the crt...).Is there anyway i can turn off this specific optimization feature?I tried all sorts of linker switches; none of which worked properly.
February 19, 201213 yr look here:/>http://www.benshoof.org/blog/minicrt/you can further optimize the minicrt code with inline assembly and stuff....
February 19, 201213 yr Author thanks, i am aware of minicrt, using it in quiet some projects. However, in this case i make extensive use of advanced crt features, so that`s not an option. I also doubt it would solve the problem...? anyways, the easiest solution is while(tlen++ < total){ _asm{NOP} *str++ = leChar;} which effectively prevents the memset optimization. I still dont see how memset is an optimization, though. It takes more space and is slower. Edited February 19, 201213 yr by deepzero
February 19, 201213 yr I had some kind of workaround back then. Something like outsourcing the code in question (in your case the loop) into a __forceinline function with #pragma optimize("", off) and on around it, respectively.
Create an account or sign in to comment