Passing of changed variables only in C++
<p>I need some help to make my code more efficient. The codelines do what I want , but it is
poorly done. I need it to be more efficient as I later will increase the amount of data and then the functions will be too slow.</p>

<p>I'm a newcomer too C++ and programming, so any suggestion are welcomed so I can learn more.</p>

<p>AS there are very few changes most of the time I just want the changed values in function A to be sent further by the function B. Now in my codes every values are sent further on even when not changes at all. This is waste of resources and not good programming, I know.</p>

<p>Important!
1)The values of the first parameter of IOCP.sendVarData are static and can not be changed.
2) The PmdgGetVariable ("MCP_annunFD", &amp;result) in function B initiate everything.
What would be the best way to improve this this?</p>

<p>I have the function below that detects any changes from last time it was runned and store the changes.</p>

<p>// This function is called when NGX data changes
void ProcessNGXData (PMDG_NGX_Data *pS)
{</p>

<pre><code>if (pS-&gt;MCP_Course[0]   != NGX_MCP_Course[0]){NGX_MCP_Course[0] = pS-&gt;MCP_Course[0];}
if (pS-&gt;MCP_Course[1]   != NGX_MCP_Course[1]){NGX_MCP_Course[1] = pS-&gt;MCP_Course[1];}
if (pS-&gt;MCP_IASMach     != NGX_MCP_IASMach){NGX_MCP_IASMach     = pS-&gt;MCP_IASMach;}
if (pS-&gt;MCP_Heading     != NGX_MCP_Heading){NGX_MCP_Heading     = pS-&gt;MCP_Heading;} 
if (pS-&gt;MCP_Altitude    != NGX_MCP_Altitude){NGX_MCP_Altitude   = pS-&gt;MCP_Altitude;}
if (pS-&gt;MCP_VertSpeed   != NGX_MCP_VertSpeed){NGX_MCP_VertSpeed = pS-&gt;MCP_VertSpeed;}

if (pS-&gt;MCP_annunLVL_CHG != NGX_MCP_annunLVL_CHG){NGX_MCP_annunLVL_CHG = pS-&gt;MCP_annunLVL_CHG;}


if (pS-&gt;MCP_annunN1         != NGX_MCP_annunN1)     {NGX_MCP_annunN1 =      pS-&gt;MCP_annunN1;}
if (pS-&gt;MCP_annunSPEED      != NGX_MCP_annunSPEED)  {NGX_MCP_annunSPEED =   pS-&gt;MCP_annunSPEED;}
if (pS-&gt;MCP_annunVNAV       != NGX_MCP_annunVNAV)   {NGX_MCP_annunVNAV =    pS-&gt;MCP_annunVNAV;}
if (pS-&gt;MCP_annunLVL_CHG    != NGX_MCP_annunLVL_CHG){NGX_MCP_annunLVL_CHG = pS-&gt;MCP_annunLVL_CHG;}
if (pS-&gt;MCP_annunHDG_SEL    != NGX_MCP_annunHDG_SEL){NGX_MCP_annunHDG_SEL = pS-&gt;MCP_annunHDG_SEL;}
if (pS-&gt;MCP_annunLNAV       != NGX_MCP_annunLNAV)   {NGX_MCP_annunLNAV =    pS-&gt;MCP_annunLNAV;}
if (pS-&gt;MCP_annunVOR_LOC    != NGX_MCP_annunVOR_LOC){NGX_MCP_annunVOR_LOC = pS-&gt;MCP_annunVOR_LOC ;}
if (pS-&gt;MCP_annunAPP        != NGX_MCP_annunAPP )   {NGX_MCP_annunAPP  =    pS-&gt;MCP_annunAPP ;}
if (pS-&gt;MCP_annunALT_HOLD   != NGX_MCP_annunALT_HOLD){NGX_MCP_annunALT_HOLD = pS-&gt;MCP_annunALT_HOLD ;}
if (pS-&gt;MCP_annunVS         != NGX_MCP_annunVS )    {NGX_MCP_annunVS  =      pS-&gt;MCP_annunVS ;}
if (pS-&gt;MCP_annunCMD_A      != NGX_MCP_annunCMD_A ) {NGX_MCP_annunCMD_A  =  pS-&gt;MCP_annunCMD_A ;}
if (pS-&gt;MCP_annunCWS_A      != NGX_MCP_annunCWS_A ) {NGX_MCP_annunCWS_A  =  pS-&gt;MCP_annunCWS_A ;}
if (pS-&gt;MCP_annunCMD_B      != NGX_MCP_annunCMD_B ) {NGX_MCP_annunCMD_B  =  pS-&gt;MCP_annunCMD_B ;}
if (pS-&gt;MCP_annunCWS_B      != NGX_MCP_annunCWS_B)  {NGX_MCP_annunCWS_B  =  pS-&gt;MCP_annunCWS_B ;}
}
</code></pre>

<p>In another thread I now have this function to send the </p>

<pre><code>static UINT running_as_Thread(LPVOID lpvoid) {
            int  result;
            bool rep= true;
            while (rep){
            PmdgGetVariable ("MCP_annunFD", &amp;result);       
            IOCP.sendVarData ( 2534, NGX_MCP_Course [0]);
            IOCP.sendVarData ( 2524,  NGX_MCP_Altitude);
            IOCP.sendVarData ( 2542, NGX_MCP_Heading);
            IOCP.sendVarData ( 2559, NGX_MCP_IASMach);
            IOCP.sendVarData ( 1140, NGX_MCP_VertSpeed);
            IOCP.sendVarData ( 2535, NGX_MCP_Course [1]);   
            IOCP.sendVarData ( 286, NGX_MCP_annunLVL_CHG);  
            IOCP.sendVarData ( 1143, NGX_MCP_VertSpeedBlank);   
            IOCP.sendVarData ( 1115, NGX_MCP_IASBlank); 
            IOCP.sendVarData ( 1117 , NGX_MCP_IASOverspeedFlash);       
            IOCP.sendVarData ( 1118, NGX_MCP_IASUnderspeedFlash);           
            IOCP.sendVarData ( 282, NGX_MCP_annunATArm);
            IOCP.sendVarData ( 283, NGX_MCP_annunN1);
            IOCP.sendVarData ( 284, NGX_MCP_annunSPEED);
            IOCP.sendVarData ( 285, NGX_MCP_annunVNAV);
            IOCP.sendVarData ( 286, NGX_MCP_annunLVL_CHG);
            IOCP.sendVarData ( 287, NGX_MCP_annunHDG_SEL);
            IOCP.sendVarData ( 288, NGX_MCP_annunLNAV);
            IOCP.sendVarData ( 289, NGX_MCP_annunVOR_LOC);
            IOCP.sendVarData ( 290, NGX_MCP_annunAPP);
            IOCP.sendVarData ( 291, NGX_MCP_annunALT_HOLD);
            IOCP.sendVarData ( 292, NGX_MCP_annunVS);
            IOCP.sendVarData ( 293, NGX_MCP_annunCMD_A);
            IOCP.sendVarData ( 294, NGX_MCP_annunCWS_A);
            IOCP.sendVarData ( 295, NGX_MCP_annunCMD_B);    
            IOCP.sendVarData ( 296, NGX_MCP_annunCWS_B);
Sleep (400);
}
    return THREAD_EXIT_OK;
}
</code></pre>
