复制拷贝 byte数组,应该用哪个API????
截取一个byte[]中的 任意和byre[]复制拷贝 给另一个 byte[],应该用哪个API????
C#有函数可以实现!!Buffer.BlockCopy
但我的目的是哟啊知道实现这个功能用哪个API函数??!!!
请问应该用哪个???
------解决方案-------------------- memcpy(源地址,目标地址,长度)
原地址 byte[] a = {1,2,3,4,5,6,7}
目标地址 byte[] b = new byte[3];
截取 a 中 3,4,5 拷贝到 b
memcpy(源地址,远地址第2下标,远地址第4下标,目标地址,长度)
???
这样怎么写?????
c++里
memcpy(a+3,b,3);
------解决方案----------------------------------------------
Red_angelX(八戒) ( ) 信誉:100 Blog 加为好友 2007-04-18 14:45:06 得分: 0
没有CopyMemory这个API 只有Rtl**CopyMemory
memcpy似乎是标准库里面的函数 我寒了...
--------------------------
CopyMemory
The CopyMemory function copies a block of memory from one location to another.
VOID CopyMemory(
PVOID Destination, // pointer to address of copy destination
CONST VOID *Source, // pointer to address of block to copy
DWORD Length // size, in bytes, of block to copy
);
Parameters
Destination
Pointer to the starting address of the copied block 's destination.
Source
Pointer to the starting address of the block of memory to copy.
Length
Specifies the size, in bytes, of the block of memory to copy.
Return Values
This function has no return value.
Remarks
If the source and destination blocks overlap, the results are undefined. For overlapped blocks, use the MoveMemory function.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
See Also
Memory Management Overview, Memory Management Functions, CopyMemoryVlm, FillMemory, FillMemoryVlm, MoveMemory, MoveMemoryVlm, ZeroMemory
------解决方案--------------------下面是Buffer.BlockCopy调用的实际C++代码,没有直接API,分32位和64位两种方式调用。
#if defined(_X86_)
//This is a replacement for the memmove intrinsic.
//It performs better than the CRT one and the inline version.
// On WIN64 the CRT implementation of memmove is actually faster than the CLR implementation of m_memmove().
void m_memmove(BYTE* dmem, BYTE* smem, int size)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_COOPERATIVE;
PRECONDITION(CheckPointer(dmem));
PRECONDITION(CheckPointer(smem));
PRECONDITION(size > = 0);
SO_TOLERANT;
}
CONTRACTL_END;
#if defined(_WIN64) || defined(ALIGN_ACCESS)
// Bail out and use the slow version if the destination and the source don 't have the same alignment.
if ( ( ((SIZE_T)dmem) & (sizeof(SIZE_T) - 1) ) !=
( ((SIZE_T)smem) & (sizeof(SIZE_T) - 1) ) )
{
memmove(dmem, smem, size);
}
else
#endif // _WIN64 || ALIGN_ACCESS
if (dmem <= smem)
{
// make sure the destination is pointer-aligned
while (( ((SIZE_T)dmem) & (sizeof(SIZE_T) - 1) ) != 0 && size > = (int)(sizeof(SIZE_T) - 1))
{
*dmem++ = *smem++;
size -= 1;
}
// copy 16 bytes at a time
if (size > = 16)
{
size -= 16;
do
{
((DWORD *)dmem)[0] = ((DWORD *)smem)[0];