Questions tagged [memcpy]

memcpy() is a C standard library function used for copying a block of memory bytes from one place to another.

Synopsis

#include <string.h>

void *memcpy(void * restrict s1,
     const void * restrict s2,
     size_t n);

Description
The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

Returns
The memcpy function returns the value of s1.

1578 questions
6
votes
0 answers

Why am I seeing more RFO (Read For Ownership) requests using REP MOVSB than with vmovdqa

Checkout Edit3 I was getting the wrong results because I was measuring without including prefetch triggered events as discussed here. That being said AFAIK I am only see a reduction in RFO requests with rep movsb as compared to Temporal Store memcpy…
Noah
  • 1,647
  • 1
  • 9
  • 18
6
votes
6 answers

How can I copy a repeating pattern into a memory buffer?

I want write a repeating pattern of bytes into a block of memory. My idea is to write the first example of the pattern, and then copy it into the rest of the buffer. For example, if I start with this: ptr: 123400000000 Afterward, I want it to look…
Daniel
  • 30,896
  • 18
  • 85
  • 139
6
votes
1 answer

streaming loads and non USWC memory

I just read this rather interesting article, Copying Accelerated Video Decode Frame Buffers. Where they explain how to do copying from USWC memory as fast as possible using streaming loads. My question is why this technique would not also speed up…
ronag
  • 49,529
  • 25
  • 126
  • 221
6
votes
4 answers

memcpy copying partly over itself

Is this ok? char buf[] = { 0, 1, 2 }; memcpy(buf, buf + 1, 2); Does having a bigger datatype make any difference? I know I could use memmove(), but I'm just curious.
Stockhausen
  • 287
  • 5
  • 13
6
votes
2 answers

Blit faster than conditional + pointer increment?

This is my simple blitting function: static void blit8(unsigned char* dest, unsigned char* src) { byte i; for (i = 0; i < 8; ++i) { if (*src != 0) { *dest = *src; } ++dest; ++src; } } I'm…
Accumulator
  • 873
  • 1
  • 13
  • 34
6
votes
1 answer

Is there a best practice when a type should be boxed?

In C#, there are structs and classes. Structs are usually (i.e. there are exceptions) stack allocated and classes are always heap allocated. Class instances, therefore, put pressure on the GC and are considered "slower" than structs. Microsoft has a…
Noel Widmer
  • 4,444
  • 9
  • 45
  • 69
6
votes
3 answers

Can I use memcmp along with qsort?

I am making C dynamic array library, kind of. Note that I'm doing it for fun in my free time, so please do not recommend million of existing libraries. I started implementing sorting. The array is of arbitrary element size, defined as…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
6
votes
2 answers

Why does wmemcpy exist when memcpy should suffice?

wmemcpy appears to perform the same operations as memcpy but accepts wchar_t* instead of void*. How is its existence justified if these two code snippets should have the same behaviour? Does it have a useful purpose? memcpy(dest, wchar_array,…
Jordan Melo
  • 1,193
  • 7
  • 26
6
votes
1 answer

Java unsafe memory copy

Does Java unsafe API support memcpy from JVM primitive array into direct memory? Note, existing call unsafe.copyMemory() copies from src to dst in the direct memory. I am interested in both writing and reading from direct memory in bulk. byte…
Vortex
  • 789
  • 12
  • 21
6
votes
2 answers

Do any compilers transfer effective type through memcpy/memmove

According to N1570 6.5/6: If a value is copied into an object having no declared type using memcpy or memmove, or is copied as an array of character type, then the effective type of the modified object for that access and for subsequent…
supercat
  • 77,689
  • 9
  • 166
  • 211
6
votes
2 answers

Understanding the copy done by memcpy()

I have to create an image which has two times the number of columns to that of the original image. Therefore, I have kept the width of the new image two times to that of the original image. Although this is a very simple task and I have already done…
skm
  • 5,015
  • 8
  • 43
  • 104
6
votes
1 answer

Understanding CUDA profiler output (nvprof)

I'm just looking at the following output and trying to wrap my mind around the numbers: ==2906== Profiling result: Time(%) Time Calls Avg Min Max Name 23.04% 10.9573s 16436 666.67us 64.996us 1.5927ms …
Pavel
  • 7,436
  • 2
  • 29
  • 42
6
votes
3 answers

Determining size of data[0] in AVFrame of FFMPEG

I am trying to allocate AVFrame->data[0] of a video frame to uint8_t* buffer using the following lines of code : size_t sizeOfFrameData = mpAVFrameInput->linesize[0] * mpAVFrameInput->height; memcpy(mFrameData, mpAVFrameInput->data[0],…
user2742299
6
votes
4 answers

C strange array behaviour

After learning that both strncmp is not what it seems to be and strlcpy not being available on my operating system (Linux), I figured I could try and write it myself. I found a quote from Ulrich Drepper, the libc maintainer, who posted an…
LukeN
  • 5,590
  • 1
  • 25
  • 33
6
votes
2 answers

convert vector to int

I have a vector of bool which I want to copy in a int container of bigger size. Is there a fast way to do this? To clarify, is there a smarter way to achieve this? #include #include #include #include #include…
magu_
  • 4,766
  • 3
  • 45
  • 79