Write implementation of memcpy and memmove functions? What is the difference between the two?

Implementation of memcpy

void memcpy(void* dest, void* src, int n_size) {
char* d = (char*) dest;
char* s = (char*) src;
while(n_size– > 0) {
*d++ = *s++;
}
}

Implementation of memmove

void memmove(void* dest, void* src, int n_size) {
char* d = (char*) dest;
char* s = (char*) src;
if(d > s) {
while(n_size– > 0) {
*d– = *s–;
}
} else {
while(n_size– > 0) {
*d++ = *s++;
}
}
}

memmove ensure correct copying when the two buffers overlap.

Related Post

Difference between HashTable and HashMap
Describe OOPs concepts in Java
See Servlet Spec 2.3, section 9.7.2
Write a function to reverse the words in a string? (e.g. “Your time has come” – > “come has time Your”)
What is an interface?

Comments

Leave a Reply




Technology