memcpy实现

源码参考:内存地址如果字对齐用字拷贝速度更快

 void *memcpy(void *dst, const void *src, size_t len)
 {
         size_t i;
         if ((uintptr_t)dst % sizeof(long) == 0 &&
             (uintptr_t)src % sizeof(long) == 0 &&
             len % sizeof(long) == 0) {
 
                 long *d = dst;
                 const long *s = src;
 
                 for (i=0; i

实现+考虑内存重叠

void* memcpy(void* dest , const void* src, size_t len)
{
	if(!dest || !src) return NULL;
	
	char* p_dest = dest;
	int i = 0;
	int n = len;
	
	if(dest > src && dest < src+n)
	{
		while(--n >= 0)
		{
			*(dest+n) = *(src+n)
		}
	}
	else
	{
		while(i

你可能感兴趣的:(C语言)