CopyMemory in Xcode

Discussion in 'Mac Programming' started by Shalako, Feb 19, 2012.

  1. macrumors newbie

    Joined:
    Feb 19, 2012
    #1
    Hello,

    I am new to Xcode and Objective C. I normally use RealStudio but I need to covert some C++ into Objective C so I can compile a dylib for a poker program project. So far I have converted everything over ok except a few lines containing this CopyMemory function:

    CopyMemory (m_ucTotalSuit, m_ucBoardSuit, 4);

    I believe this is a windows API of some sort. Does anybody know what the equivalent would be in Xcode/Obj C? Any help would be greatly appreciated.

    Thanks
     
  2. subsonix, Feb 19, 2012
    Last edited: Feb 19, 2012

    macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    It looks like memcpy(), which is a standard C function available everywhere. This suggests perhaps that it's not quite like memcpy()? If the line you have there copies 4 bytes from m_ucBoardSuit to m_ucTotalSuit, then it is. But it can differ in other ways like error handling and so on?

    Edit: just found out (from Google) that CopyMemory is nothing but a macro for memcpy(), stupid Microsoft. So you could probably try this:

    Code:
    #define CopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
     
  3. macrumors 6502a

    Joined:
    Nov 9, 2010
    #3
    Without knowing what m_ucTotalSuit and m_ucBoardSuit really are, in Objective C there's

    memcpy()

    BUT: This simply copies memory regions, it does not deal with reference counting or anything. It purely copies bztes from one location to another.

    It has no meaning in the lifecycle of your objects. So if these variables above are indeed objects you probably want to "clone" them.

    PS: Convert them into Obj-C classes and duplicate them by implementing NSCopying.

    Without knowing your code, it's really hard to tell.

    EDIT: subsonix beat me ;)
     
  4. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #4
    I'll give you some really great help, that will serve you well for many years to come. Here we go:

    You have Safari running already. Decide what you want to learn about, in your case "CopyMemory". Enter the term into the Google search box and hit return. In this case, it gets you straight to the MSDN article describing what the function does.

    So what is the Standard C function that does exactly the same thing as CopyMemory? And what is the Standard C function that does exactly the same thing as MoveMemory, which is explained about half down the page?

    (Guys, PLEASE don't mention the names of these functions. If someone cannot use Google, learning that is the topmost priority, and anything keeping them from learning to use Google is just damaging. )

    Edit: Sadly, too late.
     
  5. thread starter macrumors newbie

    Joined:
    Feb 19, 2012
    #5
    Code:
    #define CopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
    Thank you for the fast reply. I tried that and still got the same error:

    error: 'memcpy' was not declared in this scope

    I am so out of my league on this project but I am determined to figure it out so I have at least some Xcode experience.
     
  6. macrumors 6502a

    Joined:
    Nov 9, 2010
    #6
    Learning Xcode and Objective C by porting windows code is a questionable approach anyways.

    There are tons of examples in the documentation anyways.
    Learning something new sometimes requirees forgetting what you already learned....
     
  7. thread starter macrumors newbie

    Joined:
    Feb 19, 2012
    #7
    Thanks for all of the help. I fixed it by including:

    #include <string.h>

    I really am a novice!
     

Share This Page