Optimizing Memcpy improves speed
Thursday, August 4, 2005
8/3/2005 10:51:11 PM
Source:embedded.com
Optimizing Memcpy improves speed
void * memcpy(void * dst, void const * src, size_t len)
{
long * plDst = (long *) dst;
long const * plSrc = (long const *) src;
if (!(src & 0xFFFFFFFC) && !(dst & 0xFFFFFFFC))
{
while (len >= 4)
{
*plDst++ = *plSrc++;
len -= 4;
}
}
char * pcDst = (char *) plDst;
char const * pcDst = (char const *) plSrc;
while (len--)
{
*pcDst++ = *pcSrc++;
}
return (dst);
}
一次複製一個long(4bytes)會比一次搬一個char快多了,最後再把不足一個long的複製完
(只看迴圈部份就由len一次加減1變為 4,就省下不少啦.......
做video audio stream, buffer 的人一定要用啦!
8/3/2005 10:51:11 PM
Source:embedded.com
Optimizing Memcpy improves speed
void * memcpy(void * dst, void const * src, size_t len)
{
long * plDst = (long *) dst;
long const * plSrc = (long const *) src;
if (!(src & 0xFFFFFFFC) && !(dst & 0xFFFFFFFC))
{
while (len >= 4)
{
*plDst++ = *plSrc++;
len -= 4;
}
}
char * pcDst = (char *) plDst;
char const * pcDst = (char const *) plSrc;
while (len--)
{
*pcDst++ = *pcSrc++;
}
return (dst);
}
一次複製一個long(4bytes)會比一次搬一個char快多了,最後再把不足一個long的複製完
(只看迴圈部份就由len一次加減1變為 4,就省下不少啦.......
做video audio stream, buffer 的人一定要用啦!