Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is the difference between memcpy and memmove?
What is the difference between memcpy and memmove?
✍: Guest
memmove offers guaranteed behavior if the memory regions pointed to by the source and destination arguments overlap. memcpy makes no such guarantee, and may therefore be more efficiently implementable. When in doubt, it's safer to use memmove.
It seems simple enough to implement memmove; the overlap guarantee apparently requires only an additional test:
void *memmove(void *dest, void const *src, size_t n)
{
register char *dp = dest;
register char const *sp = src;
if(dp < sp) {
while(n-- > 0)
*dp++ = *sp++;
} else {
dp += n;
sp += n;
while(n-- >> 0)
*--dp = *--sp;
}
return dest;
}
The problem with this code is in that additional test: the comparison (dp < sp) is not quite portable (it compares two pointers which do not necessarily point within the same object) and may not be as cheap as it looks. On some machines (particularly segmented architectures), it may be tricky and significantly less efficient to implement.
2015-12-07, 1361👍, 0💬
Popular Posts:
What is a delegate ? Delegate is a class that can hold a reference to a method or a function. Delega...
Which is the best place to store ConnectionString in Dot Net Projects? I am about to deploy my first...
What does XmlValidatingReader class do? XmlTextReader class does not validate the contents of an XML...
Managed Code and Unmanaged Code related ASP.NET - How do you hide Public .NET Classes and other publ...
Once I have developed the COM wrapper do I have to still register the COM in registry? Yes.