Pvoid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eoinward
    New Member
    • Jul 2007
    • 2

    #1

    Pvoid

    Hi stuck with something,
    I want to copy the value of temp1 to Buffer,
    It copys across ok with no errors but the values, as printed out below are different.

    temp1, 2156
    buffer, 3361736

    ////////////////////////////////////////////////
    code snippit
    //////////////////////////////////////////

    PVOID Buffer;

    Buffer = new UCHAR[512];

    unsigned __int64 temp1 = clock();

    memcpy(Buffer,& temp1,512);

    printf("\ntemp1 ,%d",temp1);

    printf("\nbuffe r,%d \n",Buffer);

    ////////////////////////////////////////////////

    Kind Regards
    Eoin
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Do I read this right?
    Originally posted by eoinward
    unsigned __int64 temp1 = clock();

    memcpy(Buffer,& temp1,512);
    You are taking the return of clock(), which is a clock_t , which is a 4 byte integer and you are initializing a 64-bit integer with it. This is an 8 byte integer.

    Then you memcpy() 512 bytes from that __int64 to buffer??? You only own 8 bytes.

    What is it you are trying to do?

    Comment

    • eoinward
      New Member
      • Jul 2007
      • 2

      #3
      Yes seems like i had quite a few mistakes there, just need them pointed out

      Code:
      PVOID Buffer; 
      Buffer = new UCHAR[512];   //the size of the buffer
      unsigned int temp1 = clock();
      memcpy(&Buffer,&temp1,sizeof(temp1));
      fixed up the the number of bytes i was sending using sizeof();
      set temp to just 4 bytes;
      and I had forgot the & before Buffer when using memcpy,
      so i was getting the memory location address rather the the value.

      copying across perfect now, thanks for the help

      Regards
      Eoin

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Are you sure it's working perfectly??

        Originally posted by eoinward
        memcpy(&Buffer, &temp1,sizeof(t emp1));
        temp1 is an unsigned int. sizeof(temp1) is the size of an unsigned int. 4 bytes.

        Don't you mean:
        [code=c]
        memcpy(&Buffer, &temp1,sizeo f (Buffer));
        [/code]

        ???

        I mean, that's what you had in your original code.

        This is why I never use memcpy().

        Comment

        Working...