Generic keyCompare method
<p>please look through the following program..</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;malloc.h&gt;
#include &lt;iostream&gt;
#include &lt;string.h&gt;

using namespace std;

int main()
{
    char *key1 = (char*)malloc(sizeof(char)*26);
    char *key2 = (char*)malloc(sizeof(char)*26);


    int intkey1 = 10;
    int intkey2 = 10;

    float floatkey1 = 13.5f;
    float floatkey2 = 13.5f;

    double doublekey1 = 18.5;
    double doublekey2 = 18.5;

    char charkey1[10] = "nikhil";
    char charkey2[10] = "nikhil";

    //cout&lt;&lt;sizeof(int)&lt;&lt;" "&lt;&lt;sizeof(float)&lt;&lt;" "&lt;&lt;sizeof(double)&lt;&lt;endl;

    memcpy(key1,&amp;intkey1,sizeof(int));
    memcpy(key2,&amp;intkey2,sizeof(int));

    int offset = sizeof(int);

    memcpy(&amp;key1[offset],&amp;floatkey1,sizeof(float));
    memcpy(&amp;key2[offset],&amp;floatkey2,sizeof(float));

    offset = offset + sizeof(float);

    memcpy(&amp;key1[offset],&amp;doublekey1,sizeof(double));
    memcpy(&amp;key2[offset],&amp;doublekey2,sizeof(double));

    offset = offset + sizeof(double);

    memcpy(&amp;key1[offset],charkey1,sizeof(charkey1));
    memcpy(&amp;key2[offset],charkey2,sizeof(charkey2));


    int diff = memcmp(key1,key2,26);
    if( diff &gt; 0)
        cout&lt;&lt;"Key1 is greater than key2"&lt;&lt;endl;
    else if(diff &lt; 0)
        cout&lt;&lt;"Key1 is smaller than key2"&lt;&lt;endl;
    else
        cout&lt;&lt;"Both keys are equal"&lt;&lt;endl;
}
</code></pre>

<p>I am developing a B+ tree for a database engine for which i need a generic keyCompare method...Is this way of comparing byte streams by memcpy always the safe and foolproof or should i need to compare based on the types of the fields present in char key that i get from scanning column information present in the database engine? IS this fastest?</p>
