### Optimize String Manipulation

The handling of string operations can affect the performance of your program.

- When you store strings into allocated storage, align the start of the string on a 4-byte boundary. This allows the best performance of the string functions. The compiler performs this alignment for all strings it allocates.
- Keep track of the length of your strings. If you know the length of your string, you can use mem functions instead of str functions For example, memcpy is faster than strcpy because it does not have to search for the end of the string.
- Avoid using strtok. Because this function is very general, you can probably write a function more specific to your application and get better performance.
- When manipulating strings using mem functions, the code you generate will be faster if the count parameter is a constant, rather than a variable.This is especially true for small count values.

Strings are read-only by default. Placing strings into read-only memory allows for certain types of optimizations and also causes the compiler to put out only one copy of strings that are used in more than one place. If you use the intrinsic string functions, the compiler can better optimize them if it knows that any string literals it is operating on will not be changed.

Note: You can explicitly set strings to read-only by using #pragma strings (readonly) in your source files or the /qro compiler option to avoid changing your source files.

Overview of Optimization

Optimize Your Application