memcpy如下所示使用它是否更好,或者std::copy()在性能方面更好用?为什么?
char *bits = NULL;
...
bits = new (std::nothrow) char[((int *) copyMe->bits)[0]];
if (bits == NULL)
{
cout << "ERROR Not enough memory.\n";
exit(1);
}
memcpy (bits, copyMe->bits, ((int *) copyMe->bits)[0]);
Run Code Online (Sandbox Code Playgroud) 如果我不正确,下面的代码用于将字节数组复制到C#中的内存位置:
byte[] byteName = Encoding.ASCII.GetBytes("Hello There");
int positionMemory = getPosition();
Marshal.Copy(byteName, 0, new IntPtr(positionMemory), byteName.length);
Run Code Online (Sandbox Code Playgroud)
如何在本机C++中实现这一点?
提前致谢.