Click here to Skip to main content
16,005,181 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Efficiency Pin
Alain Rist3-Mar-10 3:53
Alain Rist3-Mar-10 3:53 
AnswerRe: Efficiency Pin
Alan Balkany3-Mar-10 4:22
Alan Balkany3-Mar-10 4:22 
GeneralRe: Efficiency Pin
Covean3-Mar-10 4:35
Covean3-Mar-10 4:35 
GeneralRe: Efficiency Pin
Alan Balkany3-Mar-10 4:41
Alan Balkany3-Mar-10 4:41 
GeneralRe: Efficiency Pin
CPallini3-Mar-10 7:12
mveCPallini3-Mar-10 7:12 
AnswerRe: Efficiency Pin
Chris Losinger3-Mar-10 5:04
professionalChris Losinger3-Mar-10 5:04 
AnswerRe: Efficiency Pin
supercat93-Mar-10 9:19
supercat93-Mar-10 9:19 
AnswerRe: Efficiency [modified] Pin
Covean3-Mar-10 20:42
Covean3-Mar-10 20:42 
Option C: Laugh | :laugh:
(but its only reasonable if you can't inline the foo function)

In this example you just have to call foo() (what will be "inlined" be the compiler)
At the first call it calls _FooFuncAndSetBool. There it sets the bool value bWasFooEverCalled
and after that it set the function pointer to the function _FooFuncWithoutSetBool.
Every later "inlined" call to foo() will just call you funtion without setting or checking
a value.
But as I mentioned before its only reasonable if your foo() funtion itself can't be inlined,
because there will always be a call statement in assembler and call statements are
always slower then "inlining" a function.

And now the CODE: (I hope its not that cruel Big Grin | :-D )

typedef void FooFunc();
void _FooFuncAndSetBool();
void _FooFuncWithoutSetBool();

bool bWasFooEverCalled = false;
FooFunc* pFooFunctionToCall = &_FooFuncAndSetBool;

void _FooFuncAndSetBool()
{
    bWasFooEverCalled = true;
    pFooFunctionToCall = &_FooFuncWithoutSetBool;
    _FooFuncWithoutSetBool();
}

void _FooFuncWithoutSetBool()
{
    // do something
}

inline void Foo()
{
    (*pFooFunctionToCall)();
}


Maybe this is an alternative for you.

[edit] Added the call _FooFuncWithoutSetBool() to _FooFuncAndSetBool().
Greetings
Covean
modified on Thursday, March 4, 2010 6:48 AM

Questionbind(...) in tcp is failed when connected twice C++ Pin
janaswamy uday3-Mar-10 2:14
janaswamy uday3-Mar-10 2:14 
AnswerRe: bind(...) in tcp is failed when connected twice C++ Pin
Eugen Podsypalnikov3-Mar-10 3:03
Eugen Podsypalnikov3-Mar-10 3:03 
GeneralRe: bind(...) in tcp is failed when connected twice C++ Pin
janaswamy uday3-Mar-10 3:34
janaswamy uday3-Mar-10 3:34 
GeneralRe: bind(...) in tcp is failed when connected twice C++ Pin
Eugen Podsypalnikov3-Mar-10 3:44
Eugen Podsypalnikov3-Mar-10 3:44 
GeneralRe: bind(...) in tcp is failed when connected twice C++ Pin
janaswamy uday3-Mar-10 3:48
janaswamy uday3-Mar-10 3:48 
QuestionError while trying to implement KeyLogger Pin
avika3-Mar-10 1:30
avika3-Mar-10 1:30 
AnswerMessage Removed Pin
3-Mar-10 2:15
Hristo-Bojilov3-Mar-10 2:15 
GeneralRe: Error while trying to implement KeyLogger Pin
CPallini3-Mar-10 2:21
mveCPallini3-Mar-10 2:21 
AnswerRe: Error while trying to implement KeyLogger Pin
KingsGambit3-Mar-10 7:31
KingsGambit3-Mar-10 7:31 
QuestionError in calling EXE in custom action (Setup & deployment project) Pin
am 20093-Mar-10 1:17
am 20093-Mar-10 1:17 
AnswerRe: Error in calling EXE in custom action (Setup & deployment project) Pin
KarstenK3-Mar-10 1:33
mveKarstenK3-Mar-10 1:33 
AnswerRe: Error in calling EXE in custom action (Setup & deployment project) Pin
KingsGambit3-Mar-10 7:34
KingsGambit3-Mar-10 7:34 
QuestionProblem Converting CString to WCHAR Pin
TheFox3-Mar-10 0:16
TheFox3-Mar-10 0:16 
AnswerRe: Problem Converting CString to WCHAR Pin
Rajesh R Subramanian3-Mar-10 0:28
professionalRajesh R Subramanian3-Mar-10 0:28 
AnswerRe: Problem Converting CString to WCHAR Pin
CPallini3-Mar-10 0:31
mveCPallini3-Mar-10 0:31 
GeneralRe: Problem Converting CString to WCHAR Pin
TheFox3-Mar-10 2:32
TheFox3-Mar-10 2:32 
GeneralRe: Problem Converting CString to WCHAR Pin
CPallini3-Mar-10 3:27
mveCPallini3-Mar-10 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.