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
3
votes
2 answers
C language wrong output of memove() function?
can't figure out why i got this output from this code.
#include
#include
int main()
{
char str[] = "I live in NY city";
printf("%s%s\n","The string in array str[] before invokihg the function memmove(): ",str);
…

Stanley
- 394
- 1
- 13
3
votes
1 answer
Trying to recode memmove in asm
I am using nasm on Ubuntu 16.04, and I'm currently trying to recode the C memmove() function.
Here is my code :
BITS 64
global memmove
memmove:
push rbp
mov rbp, rsp
xor rcx, rcx
while:
cmp rcx, rdx
je…

souki
- 1,305
- 4
- 23
- 39
3
votes
2 answers
Fast memmove for x86 and +1 shift (for Move-to-front transform)
For fast MTF ( http://en.wikipedia.org/wiki/Move-to-front_transform ) i need faster version of moving a char from inside the array into the front of it:
char mtfSymbol[256], front;
char i;
for(;;) { \\ a very big loop
...
i=get_i(); \\ i…

osgx
- 90,338
- 53
- 357
- 513
3
votes
2 answers
C memory overlap?
I am trying to copy the first 16 bytes of a 32 byte string to dest.
unsigned char src[32] = "HELLO-HELLO-HELLO-HELLO-HELLO-12";
unsigned char dest[16];
memcpy(dest, src, 16); // COPY
printf("%s\n", src);
printf("%lu\n",…

desktop
- 145
- 2
- 7
3
votes
4 answers
memmove vs copying backwards
I understand that memmove in C (cstring library) handles overlaps nicely "at the cost of slower runtime" (see this post). I was wondering why this additional runtime cost? It seems to me that any overlap problem could be fixed by copying backwards…

Jonathan H
- 7,591
- 5
- 47
- 80
2
votes
1 answer
Are there optimized versions of memmove for when I know the direction?
Imagine that I am implementing inserting and deleting within a small vector. (If this is C++ then assume further that the vector elements are trivially copyable.)
When inserting into the middle of this vector (assuming that I have ascertained that…

John Yates
- 1,027
- 1
- 7
- 18
2
votes
1 answer
Writeablebitmap - scrolling 1 px to the left, what's the best way ? (AKA Where's memmove ?)
I have a writeablebitmap.
I want to scroll the contents 1 pixel to the left, and fill in a new pixelrow in the rightmost column.
In C++ I'd memmove the entire buffer 1 pixel to the left, and overwrite the last pixel of each line - but I don't know…

Pygmy
- 1,268
- 17
- 33
2
votes
1 answer
REP MOVSB for overlapped memory
I want to know if there is a difference for instruction rep movsb for overlapped and non-overlapped memory pointers in rdi and rsi?
i.e. Is there any difference in implementation of memcpy and memmove via rep movsb instruction?
In this documentation…

xperious
- 239
- 3
- 10
2
votes
1 answer
Using std::memmove to work around strict aliasing?
Can std::memmove() be used to "move" the memory to the same location to be able to alias it using different types?
For example:
#include
#include
#include
#include
struct Parts { std::uint16_t v[2u];…

jotik
- 17,044
- 13
- 58
- 123
2
votes
1 answer
Valgrind says "Source and destination overlap in memcpy" about two buffers but they seems to not overlap
LAST EDIT in the end of OP
I tested with Valgrind a function used in a project and it says "Source and destination overlap in memcpy" and gives me also "Invalid read" and "Invalid write" errors. I fixed the code in order to not overlap those two…

gc5
- 9,468
- 24
- 90
- 151
2
votes
1 answer
Fixing AddressSanitizer: strcpy-param-overlap with memmove?
I am poking around in an old & quite buggy C program. When compiled with gcc -fsanitize=address I got this error while running the program itself:
==635==ERROR: AddressSanitizer: strcpy-param-overlap: memory ranges [0x7f37e8cfd5b5,0x7f37e8cfd5b8)…

darked89
- 332
- 1
- 2
- 17
2
votes
1 answer
Memmove in Assembly
I'm trying to put this Memmove C code to assembly and don't get the supposed result.
I'm using x86-64 assembly on xubuntu and after debugging for 2 hours, I don't see where I'm wrong.
C memmove code:
#include
extern void * memmove(void…
user9597158
2
votes
2 answers
memmove implementation
In reference to the thread: memmove implementation in C, I did not understand why would there be a memory overlap for 2 different variables? i.e. is this a normal scenario that the compiler allocates same 'common space' to 2 different variables and…

name_masked
- 9,544
- 41
- 118
- 172
2
votes
1 answer
Copy a struct to a specific memory location in Rust
If I have a struct, for example:
#[derive(Clone, Copy)]
#[repr(C, packed)]
pub struct SomeData {
a: u16,
b: u64,
c: u32,
d: u16,
}
How do I copy it to a specific location in memory, e.g. to a point 0x1000 in memory efficiently?…

Hannes Karppila
- 969
- 2
- 13
- 31
2
votes
4 answers
/Does/ memmove use an intermediate buffer?
This is more a question out of curiosity than anything important, but I was just wondering about the following snippet in the memmove documentation:
Copying takes place as if an intermediate buffer were used
(emphasis mine). The formulation…

CompuChip
- 9,143
- 4
- 24
- 48