Jump to content
Tuts 4 You

MSVC08 & code optimizing


Recommended Posts


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.

Link to comment

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...? smile.png

anyways, the easiest solution is

while(tlen++ < total)
*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 by deepzero
Link to comment

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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...