PDA

View Full Version : CopyMemory in Xcode




Shalako
Feb 19, 2012, 07:35 AM
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



subsonix
Feb 19, 2012, 07:39 AM
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:

#define CopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))

pmau
Feb 19, 2012, 07:41 AM
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

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 ;)

gnasher729
Feb 19, 2012, 07:45 AM
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.

Shalako
Feb 19, 2012, 07:50 AM
#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.

pmau
Feb 19, 2012, 07:52 AM
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....

Shalako
Feb 19, 2012, 08:21 AM
Thanks for all of the help. I fixed it by including:

#include <string.h>

I really am a novice!