memmove() is a C standard library function to copy a block of memory. It work even if the source and the destination overlap.
Questions tagged [memmove]
144 questions
2
votes
0 answers
Is calling memmove or memcpy with NULL defined?
I just tested the following on my setup (gcc 4.8.2, recent uClibc), and it runs fine:
#include
int main(int argc, char **argv) {
char buf[4], fub[4] = "abc";
memmove(buf, fub, 0);
memmove(buf, NULL, 0);
memmove(NULL, fub,…

dubiousjim
- 4,722
- 1
- 36
- 34
2
votes
2 answers
Example of using memmove in place of memcpy
Difference:
If there is an overlap, use memmove in place of memcpy
Q: Could you provide a practical scenario of any C lib function where an overlap happens so memmove is used in place of memcpy?

codey modey
- 983
- 2
- 10
- 23
2
votes
1 answer
When should I use memcpy and when should I use memmove?
Is there any important difference between the memcpy and the memmove functions?
When should I use memcpy and when should I use memmove?

Zack
- 385
- 2
- 3
- 21
2
votes
1 answer
Use __np_anyptrlt in memmove?
From this link:
http://clc-wiki.net/wiki/memmove
#include /* for size_t */
void *memmove(void *dest, const void *src, size_t n)
{
unsigned char *pd = dest;
const unsigned char *ps = src;
if (__np_anyptrlt(ps, pd))
for…

echo
- 789
- 2
- 12
- 21
2
votes
4 answers
memmove vs. copying individual array elements
In CLRS chapter 2 there is an exercise which asks whether the worst-case running time of insertion sort be improved to O(n lg n). I saw this question and found that it cannot be done.
The worst-case complexity cannot be improved but would by using…

Aseem Bansal
- 6,722
- 13
- 46
- 84
2
votes
1 answer
Exception during delete[] after memmove
I have the code below which contains a dynamic array of strings. I'm having problems deallocating each individual string that is generated. I assumed I could just include a new for loop which deallocated them but that didn't work. How should I be…
saturn118
2
votes
4 answers
A better array shifting algorithm?
I have an assignment that requires me to sort a heap based C style array of names as they're being read rather than reading them all and then sorting. This involves a lot of shifting the contents of the array by one to allow new names to be…

user2211776
- 239
- 1
- 2
- 11
2
votes
2 answers
is memmove necessary for trim function in C?
I was reading a wikipedia article on Trimming and saw this implementation of ltrim (left trim)
char *
ltrim(char *str)
{
char *ptr;
int len;
for (ptr = str; *ptr && isspace((int)*ptr); ++ptr);
len = strlen(ptr);
memmove(str, ptr, len +…

Le Curious
- 1,451
- 1
- 13
- 13
1
vote
3 answers
C - memmove() function - How many bytes am I moving in this implementation?
This seems to be a great place. My question is, what value (or how many bytes) am I moving in this implementaion of memmove()?
int main ()
{
char str[] = "memmove can be very useful......";
memmove (str+15,str+20,/*?*/);
puts (str);
return 0;
}
In…

Mike mmm
- 19
- 3
1
vote
2 answers
Passing a multidimensional array as an argument in C
I am trying to initialize matrices in a helper function, but I am getting a warning accessing the matrix inside the helper function that I can't figure out how to fix. I was reading about multidimensional arrays and even saw the same notation used…

Darkonode
- 43
- 5
1
vote
1 answer
Adding and Deleting elements on a Array of Structs Using memcpy()
So I have this Contact struct and an array that holds a bunch of instances of Contact. My problem is that I use memcpy and have tried using mmove for this as well to "delete" and "add" contact elements to this array. It seems to work perfectly fine…

Jonnes
- 29
- 5
1
vote
1 answer
How to implement memmove, not just memcpy, in assembly?
I was trying to implement memmove from C into x86 assembly so I wrote:
start:
movb source(%eax), %cl
movb %cl, destination(%eax)
inc %eax
cmp num, %eax
jne start
end:
But this is wrong, why? according to:…
user15728444
1
vote
2 answers
implementing memmove without copying the source data
I need to implement myself the standard c function memmove.
void *memmove(void *str1, const void *str2, size_t n)
Can I avoid copying the source (pointed by str2) into a temporary buffer before doing the actual copy ?
Thanks!

Tomer
- 1,159
- 7
- 15
1
vote
1 answer
Is there a memmove/memcpy wrapper for STUArray?
I'm switching a program from using MVector Word32 to STUArray Word Word32. In my vector code, I used unsafeMove to move vector slices around; thinking it was probably wrapping memmove for efficiency.
case dst ⊕ 3 of
src | n < src + w -> do
let…

rampion
- 87,131
- 49
- 199
- 315
1
vote
1 answer
Is memmove copying 0 bytes but referencing out of bounds safe
I have read online that memmove is expected to perform no action if the number of bytes to copy is 0. However what I want to know is if it is expected that the source and destination pointers will not be read in that case
Below is a simplified…

asimes
- 5,749
- 5
- 39
- 76