memcpy

Is it guaranteed to be safe to perform memcpy(0,0,0)?

爱⌒轻易说出口 提交于 2019-11-27 07:09:48
I am not so well-versed in the C standard, so please bear with me. I would like to know if it is guaranteed, by the standard, that memcpy(0,0,0) is safe. The only restriction I could find is that if the memory regions overlap, then the behavior is undefined... But can we consider that the memory regions overlap here ? I have a draft version of the C standard (ISO/IEC 9899:1999), and it has some fun things to say about that call. For starters, it mentions (§7.21.1/2) in regards to memcpy that Where an argument declared as size_t n specifies the length of the array for a function, n can have the

Very fast memcpy for image processing?

旧城冷巷雨未停 提交于 2019-11-27 06:08:53
I am doing image processing in C that requires copying large chunks of data around memory - the source and destination never overlap. What is the absolute fastest way to do this on the x86 platform using GCC (where SSE , SSE2 but NOT SSE3 are available)? I expect the solution will either be in assembly or using GCC intrinsics? I found the following link but have no idea whether it's the best way to go about it (the author also says it has a few bugs): http://coding.derkeiler.com/Archive/Assembler/comp.lang.asm.x86/2006-02/msg00123.html EDIT: note that a copy is necessary, I cannot get around

Copying structure in C with assignment instead of memcpy()

天涯浪子 提交于 2019-11-27 05:36:49
问题 Up until recently, I have only seen copying of structure fields done with memcpy() . In classes and online instructions, copying the contents of one struct into another generally looks like struct block *b0 = malloc(sizeof(struct block)); struct block *b1 = malloc(sizeof(struct block)); /* populate fields in *b0 */ memcpy(b1, b0, sizeof *b1); /* copy contents of b0 into b1 */ /* free b0, b1 */ However, this task can also be accomplished by a simple assignment replacing the memcpy() . *b1 =

What is the difference between memmove and memcpy?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 02:48:00
What is the difference between memmove and memcpy ? Which one do you usually use and how? bdonlan With memcpy , the destination cannot overlap the source at all. With memmove it can. This means that memmove might be very slightly slower than memcpy , as it cannot make the same assumptions. For example, memcpy might always copy addresses from low to high. If the destination overlaps after the source, this means some addresses will be overwritten before copied. memmove would detect this and copy in the other direction - from high to low - in this case. However, checking this and switching to

memcpy(), what should the value of the size parameter be?

我只是一个虾纸丫 提交于 2019-11-27 02:43:11
问题 I want to copy an int array to another int array. They use the same define for length so they'll always be of the same length. What are the pros/cons of the following two alternatives of the size parameter to memcpy()? memcpy(dst, src, ARRAY_LENGTH*sizeof(int)); or memcpy(dst, src, sizeof(dst)); Will the second option always work? Regardless of the content? One thing that favors the last one is that if the array were to change, it'll be some house-keeping to update the memcpy()'s. Thanks 回答1:

Memcpy() in secure programming?

醉酒当歌 提交于 2019-11-27 01:37:53
问题 I recently stumbled across an article that claims Microsoft is banning the memcpy() function in its secure programming shops. I understand the vulnerabilities inherent in the function, but is it necessary to ban its use entirely? Should programs I write be avoiding memcpy() entirely, or just ensuring that it's used safely? What alternatives exist that provide similar but safer functionalilty? 回答1: Microsoft provides alternatives to memcpy and wmemcpy that validate their parameters. memcpy_s

Meaning of overlapping when using memcpy

依然范特西╮ 提交于 2019-11-26 23:39:42
问题 I am trying to understand the function memcpy() which is defined in the C library <string.h> Syntax: void *memcpy(void*dst,const void*src,size_t n); I know that this function is used to copy the contents of the memory pointed by pointer src to the location pointed by the dst pointer and return a address pointed by dst pointer. I am not able to understand the following important statement regarding memcpy() : When using memcpy() , memory address should not overlap, if it overlaps then the

Dereferencing an out of bound pointer that contains the address of an object (array of array)

為{幸葍}努か 提交于 2019-11-26 23:33:58
问题 Is the following well defined, for different values of REF ? #include <stdio.h> #define REF 1 #define S 1 int main(void) { int a[2][S] = {{1},{2}}; int *q = REF ? a[1] : 0; int *p = a[0] + S; memcpy (&q, &p, sizeof q); printf ("q[0] = %d\n", q[0]); return 0; } Note that p points to the after the last element of a[0] , not to an element in the array a[0] , hence not dereferenceable. But the address stored in p is the address of a[1][0] . p semantically (intentionally?) points "to" (well, out

How to increase performance of memcpy

人盡茶涼 提交于 2019-11-26 22:31:33
问题 Summary: memcpy seems unable to transfer over 2GB/sec on my system in a real or test application. What can I do to get faster memory-to-memory copies? Full details: As part of a data capture application (using some specialized hardware), I need to copy about 3 GB/sec from temporary buffers into main memory. To acquire data, I provide the hardware driver with a series of buffers (2MB each). The hardware DMAs data to each buffer, and then notifies my program when each buffer is full. My program

Getting GCC to compile without inserting call to memcpy

蓝咒 提交于 2019-11-26 21:34:41
问题 I'm currently using GCC 4.5.3, compiled for PowerPC 440, and am compiling some code that doesn't require libc. I don't have any direct calls to memcpy(), but the compiler seems to be inserting one during the build. There are linker options like -nostdlib, -nostartfiles, -nodefaultlibs but I'm unable to use them as I'm not doing the linking phase. I'm only compiling. With something like this: $ powerpc-440-eabi-gcc -O2 -g -c -o output.o input.c If I check the output.o with nm, I see a