• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Function argument constructor/destructor timing across dll boundary

Khanmots

Gawd
Joined
May 12, 2007
Messages
905
Supposed I have a dll with an API consisting of:
void someFunc(std::string arg);

I call it from within an MFC application as so:
someFunc("my string");

My understanding is that the constructor for std::string is called in my application's context (i.e., the memory for the string class is allocated on the stack, and then the dynamic memory internally allocated by the copy constructor is allocated on the my applications heap by my applications version of the c runtime library)

My question is, when exactly is the destructor called in relation to the return from the function call and corresponding runtime library/heap switch? Is it while still within the context of the dll? If so, I'm thinking that this would result in the dll's c runtime library attempting to delete the std::string's internal dynamically allocated storage from it's heap resulting in the apparent heap corruption I'm encountering.

Or am I barking up the wrong tree? (I'm rather new to this whole dll thing...)
 
Last edited:
I guess my question should be expanded to when does the heap context switch during function entry? And what exactly goes on with the temporary std::string? My understanding is that there's a temporary created to be fed into the call, and then that temporary is copied into a new std::string that's then given the name arg for use inside the function (although this may be compiler specific?). However, how does this interact with the heap switch? And when exactly is this temporary destroyed?

I'm starting to think I'm going to have to confuse myself no-end and try to beat my way through the disassembly. :(

Also, if I'm right in my suspicion that this is what's causing my issue, would the resolution be as simple as switching the function to take a std::string & instead?
 
Back
Top