memcpy

Preference between memcpy and dereference

不问归期 提交于 2019-12-04 21:46:06
问题 When copying a known struct in memory, would you prefer using memcpy or dereference? why? Specifically, in the following code: #include <stdio.h> #include <string.h> typedef struct { int foo; int bar; } compound; void copy_using_memcpy(compound *pto, compound *pfrom) { memcpy(pto, pfrom, sizeof(compound)); } void copy_using_deref(compound *pto, compound *pfrom) { *pto = *pfrom; } int main(int argc, const char *argv[]) { compound a = { 1, 2 }; compound b = { 0 }; compound *pa = &a; compound

SSE图像算法优化系列三十:GIMP中的Noise Reduction算法原理及快速实现。

橙三吉。 提交于 2019-12-04 19:50:52
  GIMP源代码链接: https://gitlab.gnome.org/GNOME/gimp/-/archive/master/gimp-master.zip   GEGL相关代码链接: https://gitlab.gnome.org/GNOME/gegl/-/archive/master/gegl-master.zip   最近因为要研究下色温算法,顺便下载了最新的GIMP软件,色温算法倒是找到了(有空单独来讲下),也顺便看看GIMP都有些什么更新,嗯,更新还是蛮多的,界面UI上有很多改动,有些已经改的面目全非了。随便瞄了一下Enhance菜单,发现里面有一个Nosie Reduction算法,试了下,还有点效果。于是在github上下载了GIMP的源代码,可是在源代码里搜索相关的关键词确没有发现任何的相关代码,后来才发现很多东西都有个GEGL关键词,结果一百度,原来他是一个单独的软件包,于是有下载了GEGL的源代码,终于在gegl-master\operations\common\里面看到了noise-reduction.c文件。   其核心的代码如下: static void noise_reduction (float *src_buf, /* source buffer, one pixel to the left and up from the starting

how to use movntdqa to avoid cache pollution?

余生颓废 提交于 2019-12-04 18:07:17
问题 i am trying to write a memcpy function that does not load the source memory to the cpu cache. The purpose is to avoid cache pollution. The memcpy function below works, but pollutes the cache like the standard memcpy does. i am using P8700 proccesoor with visual C++ 2008 express. i see the cpu cache usage with intel vtune. void memcpy(char *dst,char*src,unsigned size){ char *dst_end=dst+size; while(dst!=dst_end){ __m128i res = _mm_stream_load_si128((__m128i *)src); *((__m128i *)dst)=res; src+

What is the difference between memcpy() and strncpy() given the latter can easily be a substitute for the former?

ε祈祈猫儿з 提交于 2019-12-04 17:16:40
问题 What is the significant difference between memcpy() and strncpy() ? I ask this because we can easily alter strncpy() to copy any type of data we want, not just characters, simply by casting the first two non- char* arguments to char* and altering the third argument as a multiple of the size of that non-char type. In the following program, I have successfully used that to copy part of an integer array into other, and it works as good as memcpy() . #include <stdio.h> #include <string.h> int

What makes Apple's PowerPC memcpy so fast?

空扰寡人 提交于 2019-12-04 16:05:32
问题 I've written several copy functions in search of a good memory strategy on PowerPC. Using the Altivec or fp registers with cache hints (dcb*) doubles the performance over a simple byte copy loop for large data. Initially pleased with that, I threw in a regular memcpy to see how it compared... 10x faster than my best! I have no intention of rewriting memcpy, but I do hope to learn from it and accelerate several simple image filters that spend most of their time moving pixels to and from memory

C中自己的memcpy

半城伤御伤魂 提交于 2019-12-04 15:21:37
memor_copy memory_cpy // 版本 1 void *memcpy(void *dest, const void *src, size_t count) { char *tmp = dest; const char *s = src; while (count--) *tmp++ = *s++ ; // 先取出s的内容,后s+1 return dest; } //版本 2 考虑重叠 void *memcpy(void *dest, const void *src, size_t count) { char *d; const char *s; if (dest > (src+size)) || (dest < src)) { d = dest; s = src; while (count--) *d++ = *s++; } else /* overlap 重叠情况从高位到低位复制*/ { d = (char *)(dest + count - 1); /* offset of pointer is from 0 */ s = (char *)(src + count -1); while (count --) *d-- = *s--; } return dest; } 来源: https://www.cnblogs.com/htj10/p/11871363

Efficient way to copy strided data (to and from a CUDA Device)?

六月ゝ 毕业季﹏ 提交于 2019-12-04 14:07:18
问题 Is there a possibility to copy data strided by a constant (or even non-constant) value to and from the CUDA device efficiently? I want to diagonalize a large symmetric matrix. Using the jacobi algorithm there is a bunch of operations using two rows and two columns within each iteration. Since the Matrix itself is too big to be copied to the device entirely i am looking for a way to copy the two rows and columns to the device. It would be nice to use the triangular matrix form to store the

Struct inheritance vs class inheritance in C++

牧云@^-^@ 提交于 2019-12-04 09:55:43
I just discovered from this Q/A that structs are inheritable in C++ but, is it a good practice, or is it preferable to use classes? In which cases is preferable and in which ones is not? I have never needed this, but now I have a bunch of messages of different types, but same longitude. I got them in binary in a char array, and I just copy them with memcpy to the struct to fill its fields (I don't know if it is even possible to do it with std::copy). I guess it would be great to be able to inherit every struct from a base struct with common headers, that is why I searched for this. So a second

Make compiler copy characters using movsd

若如初见. 提交于 2019-12-04 05:26:36
I would like to copy a relatively short sequence of memory (less than 1 KB, typically 2-200 bytes) in a time critical function. The best code for this on CPU side seems to be rep movsd . However I somehow cannot make my compiler to generate this code. I hoped (and I vaguely remember seeing so) using memcpy would do this using compiler built-in intrinsics, but based on disassembly and debugging it seems compiler is using call to memcpy/memmove library implementation instead. I also hoped the compiler might be smart enough to recognize following loop and use rep movsd on its own, but it seems it

Do any compilers transfer effective type through memcpy/memmove

↘锁芯ラ 提交于 2019-12-04 05:22:11
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 accesses that do not modify the value is the effective type of the object from which the value is copied, if it has one. That would suggest that even on a system where "long" and some other integer type have the same representation, the following would invoke Undefined Behavior: #if ~0UL == ~0U #define long_equiv int #elif ~0UL == ~0ULL #define long_equiv long