Your analysis is a bit flawed. First of all, you don't need to empty the string before populating it:
bkelly13 wrote:
void B( CString &some_string ); // (spelling error fixed) { some_string.empty(); // this line is unnecessary some_string = internal_string; }
There are several things that happen in this (fixed) code that don't happen in the 'first call' version. When calling the API, there is more setup on the part of the caller. A CString variable needs to exist already, and API setup makes sure that it is either empty or ref count is zero (and writable). Assuming that internal_string is another CString, no copying takes place. The some_string object's header info is updated to duplicate the same info in internal_string, and the ref count is incremented. If internal_string is 1MB in size, only a pointer and counter are changed (ie. no copying). Again, if internal_string is a CString, a similar process also happens in your 'first call' code (ie. no copying). If internal_string is a (const?) char* or (const?) char[] or something else that looks like one of those, then a copy needs to take place for both versions of the code.
Windows 8 is the resurrected version of Microsoft Bob. The only thing missing is the Fisher-Price logo. - Harvey