标签:nbsp ret tmp assert 拷贝 sig space %s while
#include <iostream>
using namespace std;
#include <assert.h>
void* myMemcpy(void* dst, const void* src, size_t count);
int main(void)
{
int test[4] = {1,2,3,4};
int* src = test;
int* dst = NULL;
dst = (int*)malloc(sizeof(int)*4);
if(NULL == dst)
{
cout << "malloc memory failes" << endl;
return 0;
}
for(int i=0; i<4;i++)
{
*(dst+i)=0;
}
myMemcpy(dst, src, 4);
for(int i=0; i<4; i++)
{
cout << *(dst+i) << endl;
}
return 0;
}
void* myMemcpy(void* dst, const void* src, size_t count)
{
assert(dst != NULL && src != NULL);
int nuchunks = count/sizeof(dst);//按CPU位宽拷贝
int slices = count%sizeof(dst);//剩余的按字节拷贝
(unsigned long*)tmpDst = (unsigned long*)dst;
(unsigned long*)tmpSrc = (unsigned log*)src;
while(nuchunks--)
{
*tmpDst++ = *tmpSrc++;
}
while(slices--)
{
*((char*)tmpDst++) = *((char*)tmpSrc++);
}
return (void*)dst;
}
标签:nbsp ret tmp assert 拷贝 sig space %s while
原文地址:https://www.cnblogs.com/embeddedking/p/9656642.html