Questions tagged [memmove]

memmove() is a C standard library function to copy a block of memory. It work even if the source and the destination overlap.

144 questions
205
votes
11 answers

memcpy() vs memmove()

I am trying to understand the difference between memcpy() and memmove(), and I have read the text that memcpy() doesn't take care of the overlapping source and destination whereas memmove() does. However, when I execute these two functions on…
user534785
  • 2,173
  • 2
  • 13
  • 6
138
votes
9 answers

What is the difference between memmove and memcpy?

What is the difference between memmove and memcpy? Which one do you usually use and how?
ultraman
131
votes
2 answers

Can I call memcpy() and memmove() with "number of bytes" set to zero?

Do I need to treat cases when I actully have nothing to move/copy with memmove()/memcpy() as edge cases int numberOfBytes = ... if( numberOfBytes != 0 ) { memmove( dest, source, numberOfBytes ); } or should I just call the function without…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
40
votes
3 answers

Can memcpy or memmove return a different pointer than dest?

The function memmove is defined like this: void *memmove(void *dest, const void *src, size_t n); In the Linux manual page, it says: RETURN VALUE The memmove() function returns a pointer to dest. Why isn't the function just defined as void…
Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
19
votes
1 answer

Why is Linux memmove() implemented the way it is?

From the Linux manpage for memmove(3) The memmove() function copies n bytes from memory area src to memory area dest. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does…
MarcDefiant
  • 6,649
  • 6
  • 29
  • 49
16
votes
7 answers

What are real significant cases when memcpy() is faster than memmove()?

The key difference between memcpy() and memmove() is that memmove() will work fine when source and destination overlap. When buffers surely don't overlap memcpy() is preferable since it's potentially faster. What bothers me is this potentially. Is…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
15
votes
3 answers

How to use and when is good use memmove in C?

I have two doubts about the use of memmove(): When is it preferable to use this function instead of using another function (i.e. a created own function)? I’m not sure I have understood properly. The signature of the function is void *memmove(void…
Kyrol
  • 3,475
  • 7
  • 34
  • 46
12
votes
1 answer

How are elements of a vector left-shifted in Rust?

Is there a safe way to left-shift elements of a vector in Rust? (vec![1, 2, 3] becomes vec![3] when left-shifted two places). I'm dealing with Copy types, and I don't want to pay a penalty higher than what I would with a memmove. The only solution…
Doe
  • 585
  • 5
  • 19
10
votes
4 answers

what does the "const void*" mean in memmove?

The second arg in the prototypes for memmove/memcpy/strcpy are similar: For example: void *memmove(void *dest, const void *src, size_t n); //const void* char *strcpy(char *dest, const char *src); //const char* But apparently, if dest and src…
Alcott
  • 17,905
  • 32
  • 116
  • 173
10
votes
3 answers

memcpy vs assignment in C -- should be memmove?

As pointed out in an answer to this question, the compiler (in this case gcc-4.1.2, yes it's old, no I can't change it) can replace struct assignments with memcpy where it thinks it is appropriate. I'm running some code under valgrind and got a…
bstpierre
  • 30,042
  • 15
  • 70
  • 103
8
votes
3 answers

memmove implementation in C

Can some one help me to understand how memmove is implemented in C. I have only one special condition right ? if((src dst)) copy from the back Also does it depend on the way stack grows ?
brett
  • 5,379
  • 12
  • 43
  • 48
8
votes
2 answers

Bitwise memmove

What is the best way to implement a bitwise memmove? The method should take an additional destination and source bit-offset and the count should be in bits too. I saw that ARM provides a non-standard _membitmove, which does exactly what I need, but…
turbolent
  • 288
  • 1
  • 6
7
votes
4 answers

If destination and source are the same, what does memmove do?

If destination and source are the same, does memmove still "move" the data (or does it return directly)? What about realloc; what if the new size is the same as the old size?
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
7
votes
2 answers

How does the memory overlap occur and how is it controlled?

While reading about memmove I read that it can handle MEMORY OVERLAPSbut I am unable to get how a memmory overlap can occur between two strings and how can this function still copy the block of memory correctly.
user379888
7
votes
3 answers

Which is faster for reverse iteration, for or while loops?

I am trying to implement the standard memmove function in Rust and I was wondering which method is faster for downwards iteration (where src < dest): for i in (0..n).rev() { //Do copying } or let mut i = n; while i != 0 { i -= 1; // Do…
EpicPotato
  • 559
  • 2
  • 5
  • 12
1
2 3
9 10