@ helios: I'm curious, why would you declare that inline? It doesn't appear to be a member function.
OP wrote:
Im not that far into those type of functions yet though.
That's fine, we can explain this code if that's what you are looking for. Because you are not familiar with it though we should mention that because helios designated "std::nothrow" then in order to test for a bad allocation, like you are doing on with your try catch block, you would test the returned value for NULL.
The only time I've known the inline designation to be beneficial is when I'm writing a struct\class and for one reason or another (in my case thread injection) I don't want the compiler to move it relative to the object.
EDIT: I can except if I've been completley misusing inline this entire time. I'm still trying to break some of my bad habits.
inline is a suggestion for the compiler to copy the body of the function onto the point of call to avoid making an actual subroutine call. It can be applied to any function. In the particular case of member functions, they can be asked to be inlined without using the inline keyword.
So, please let me know if I understand you correctly.
- Due to the actual amount of work being performed by the function, you decided to make sure this function was compiled inline with it's call because pushing and popping the registers in this case would just be needless over head?
- Or was it to make sure that the memory you allocated doesn't get overwritten\deallocated because the subroutine doesn't exist so there is no call to RET? (This one was a last minute theory right before I hit submit).
The former is closer to the truth. The latter doesn't make sense.
inline is a suggestion. There's no guarantee that the code will actually get copied (some compilers have an alternative keyword that does make this guarantee). However, inline works great for short, macro-like functions like the one above.
Yeah, the second thought was a little half-baked but I was thinking that because in a C++ __stdcall() it's up to the callee to preserve and restore the memory state (ESP and EBP), not creating a subroutine would mean that you are remaining in the same Stack Frame so the memory would remain acessable. But since you're returning that address anyway it doesn't matter in the slightest.
I was thinking that because in a C++ __stdcall() it's up to the callee to preserve and restore the memory state (ESP and EBP), not creating a subroutine would mean that you are remaining in the same Stack Frame so the memory would remain acessable.
When thinking about semantics, don't think about any platform-specific details like calling conventions or registers. It will only trip you up.
inline doesn't change the semantics of a function, only the way code is generated.