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
0
votes
1 answer

How to allocate memory in the front of data

I am working with sending data to and from a client/server application. I have created my own header scheme. This is the flow I am in question about: char *data = returnmydata(); int one = 1; int two = 2; int three = 3; So what happens is I have a…
xf900
  • 35
  • 4
0
votes
1 answer

Valgrind memcpy Invalid write of size 8 (uintptr_t *)

I have an issue with memcpy and valgrind, telling me about an Invalid write of size 8. I got to the point of figuring out where the faulty code is, but I have no clue as to why it is faulty... I'm aware that there are other questions regarding that,…
rphii
  • 209
  • 2
  • 13
0
votes
2 answers

Does comparing two pointers do more than to just check their adresses?

I'm rewriting part of libc, more specifically memmove as an exercise and after being unable to do it myself I looked for its source code and found this (and variations of it): void *memmove(void *dest, const void *src, size_t n) { char *d =…
MiguelP
  • 416
  • 2
  • 12
0
votes
1 answer

Implementing an Optimized Memmove in C

I am trying to implement my own memmove function. I am trying to optimize it instead of copying byte by byte. Here is my implementation: void* my_memmove(void *dest, const void *src, size_t len) { if((uintptr_t)dest < (uintptr_t)src) …
0
votes
2 answers

How does realloc behave in C++ regarding extra Space?

Let's suppose I have allocated a block of size 40 like this: int *x=malloc(40); Now when I call realloc like this: realloc(x,100); what will happen to the other 60? Here are my suggestions. A) Will be set to 0 B) Will Contain garbage from what…
user16310948
0
votes
1 answer

Why does ctypes.memmove take constant time for sizes of different magnitudes

When I run the following code, import numpy as np import ctypes src = np.zeros(10000, dtype=np.uint8) dest = np.zeros(10000, dtype=np.uint8) %timeit ctypes.memmove(dest.ctypes.data, src.ctypes.data, 10) %timeit ctypes.memmove(dest.ctypes.data,…
Ericzz
  • 1
  • 1
0
votes
1 answer

memmove implementation throws segmentation fault while copying a character array

Hi I tried to write my own version of memmove and I find the following code resulting in a segmentation fault. It would be great if someone could help me figure out why this behavior would occur! However, when I use something like: char source[20] =…
pr123
  • 19
  • 3
0
votes
2 answers

Why does C abstract away sizeof during pointer arithmetic?

I was recreating an array from scratch in C, with implementation of common functions such as append, insert, etc. I got most of the way, but when I tried running my "insert" function at index 1 (as opposed to 0), I started getting segfault errors…
gcr
  • 443
  • 2
  • 5
  • 14
0
votes
2 answers

Trying to delete product from my list using pointer and struct

In this function, I trying to delete a product from a list. Visual Studio shows me a red line under list->itemList[i].productName = list->itemList[i + 1].productName; and list->itemList[i].unit = list->itemList[i + 1].unit; but not…
LeoParden
  • 17
  • 2
0
votes
1 answer

Seeking algorithm for "dual-modulo array memmove"

As the algorithm being requested is somewhat special, I'm trying to explain what I want first, then I'll ask concrete questions that I'm quite unsure about: Introduction The algorithm is not C-specific, but I'll start with a C-example, namely…
U. Windl
  • 3,480
  • 26
  • 54
0
votes
2 answers

Question about memmove implementation in C

I am a complete novice in C, so this might be a stupid question. In the implementations of memmove I find online, the code does the following: void *memmove(void *dest, const void *src, size_t len) { char *d = dest; const char *s = src; if(d <…
tomAwa
  • 46
  • 8
0
votes
1 answer

How Would I Use Memmove and Memset to Remove an Item In My List?

I am trying to remove an item from a list. I am lost to how I would do that with memset and memmove. Example of how I want it: Initial array: test1 1 kg test2 2 kg test3 3 kg test4 4 kg test5 5 kg After removing item 2: test1 1 kg test3 3…
zellez
  • 398
  • 2
  • 17
0
votes
3 answers

copy character string to an unsigned buffer: Segmentation fault

i am trying to copy two integers and a character string to a buffer and print the buffer elements out. I get a seg fault for the third printf statement: id = 102; len = 3; str = "working"; memmove(buffer,&message_id,sizeof(id)); …
Warz
  • 7,386
  • 14
  • 68
  • 120
0
votes
4 answers

overlapping memmove best practice

I have a question about the 3rd parm to memmove when manipulating a string. strlen(string) and strlen(string) + 1 seem to produce the same results. I would think that the +1 part would include a termination \0 but everything seems to work fine…
GoinOff
  • 1,792
  • 1
  • 18
  • 37
0
votes
1 answer

C memmove equivalent of for loop - segfault

I'm implementing ring buffer with dynamic resizing. When tail is behind head, data from the end of the buffer has to be moved to new end of buffer after resize. In order to do so I made following…
Lapsio
  • 6,384
  • 4
  • 20
  • 26