memcpy

洛谷P5158 【模板】多项式快速插值

橙三吉。 提交于 2019-11-26 20:44:12
https://www.luogu.org/problemnew/show/P5158 题解: https://www.cnblogs.com/zzqsblog/p/7923192.html 备份 版本1:基于 版本1 1 #prag\ 2 ma GCC optimize(2) 3 #include<cstdio> 4 #include<algorithm> 5 #include<cstring> 6 #include<vector> 7 #include<cmath> 8 using namespace std; 9 #define fi first 10 #define se second 11 #define mp make_pair 12 #define pb push_back 13 typedef long long ll; 14 typedef unsigned long long ull; 15 const int md=998244353; 16 const int N=262144; 17 #define delto(a,b) ((a)-=(b),((a)<0)&&((a)+=md)) 18 inline int del(int a,int b) 19 { 20 a-=b; 21 return a<0?a+md:a; 22 } 23 int rev[N]; 24

Difference between strncpy and memcpy?

荒凉一梦 提交于 2019-11-26 19:45:35
问题 How can i access s[7] in s ? I didn't observe any difference between strncpy and memcpy . If I want to print the output s , along with s[7] (like qwertyA ), what are the changes I have to made in the following code: #include <stdio.h> #include <stdlib.h> int main() { char s[10] = "qwerty", str[10], str1[10]; s[7] = 'A'; printf("%s\n",s); strncpy(str,s,8); printf("%s\n",str); memcpy(str1,s,8); printf("%s\n",str1); return 0; } /* O/P qwerty qwerty qwerty */ 回答1: Others have pointed out your

faster alternative to memcpy?

佐手、 提交于 2019-11-26 19:18:30
问题 I have a function that is doing memcpy, but it's taking up an enormous amount of cycles. Is there a faster alternative/approach than using memcpy to move a piece of memory? 回答1: memcpy is likely to be the fastest way you can copy bytes around in memory. If you need something faster - try figuring out a way of not copying things around, e.g. swap pointers only, not the data itself. 回答2: This is an answer for x86_64 with AVX2 instruction set present. Though something similar may apply for ARM

Why does the speed of memcpy() drop dramatically every 4KB?

爱⌒轻易说出口 提交于 2019-11-26 18:49:14
问题 I tested the speed of memcpy() noticing the speed drops dramatically at i*4KB. The result is as follow: the Y-axis is the speed(MB/second) and the X-axis is the size of buffer for memcpy() , increasing from 1KB to 2MB. Subfigure 2 and Subfigure 3 detail the part of 1KB-150KB and 1KB-32KB. Environment: CPU : Intel(R) Xeon(R) CPU E5620 @ 2.40GHz OS : 2.6.35-22-generic #33-Ubuntu GCC compiler flags : -O3 -msse4 -DINTEL_SSE4 -Wall -std=c99 I guess it must be related to caches, but I can't find a

Copy 2D array using memcpy?

丶灬走出姿态 提交于 2019-11-26 17:44:25
问题 So I want to copy the contents of a 2D array to another array of the exact same type. Here is how the array is created: GridUnit** newGrid; newGrid = new GridUnit*[width]; for (int i = 0; i < width; i++) newGrid[i] = new GridUnit[height]; GridUnit is size 16 (4 floats). So that's all initialised fine, no problems with using it as it is after I have ran the for loops to actually fill the values with some data. Now what I want to do is copy the contents of another array into this one (without

Can I call memcpy() and memmove() with “number of bytes” set to zero?

跟風遠走 提交于 2019-11-26 15:50:08
问题 Do I need to treat cases when I actully have nothing to move/copy with memmove() / memcpy() as edge cases int numberOfBytes = ... if( numberOfBytes != 0 ) { memmove( dest, source, numberOfBytes ); } or should I just call the function without checking int numberOfBytes = ... memmove( dest, source, numberOfBytes ); Is the check in the former snippet necessary? 回答1: From the C99 standard (7.21.1/2): Where an argument declared as size_t n specifies the length of the array for a function, n can

循环缓冲类

无人久伴 提交于 2019-11-26 14:59:36
4月27日去迈瑞面试,要求写一个循环缓冲类,真心没接触过,结果可想而知。 下午回到实验室,认真写了一下,完成代码贴出来。 1: //mindry_buffer.h 2: 3: #ifndef MINDRY_BUFFER_H_H 4: #define MINDRY_BUFFER_H_H 5: 6: class CMindryBuffer 7: { 8: public : 9: bool isFull(); //缓冲区是否满 10: bool isEmpty(); //缓冲区是否空 11: void Empty(); //置空缓冲区 12: int GetLength(); //缓冲区大小 13: 14: CMindryBuffer( int size); 15: virtual ~CMindryBuffer(); 16: 17: int Write( char * buf, int count); //写缓冲 18: int Read( char * buf, int count); //读缓冲 19: 20: private : 21: bool m_bEmpty; //缓冲区空标识 22: bool m_bFull; //缓冲区满标识 23: 24: char * m_pBuf; //缓冲区指针 25: int m_nBufSize; //缓冲区大小 26: int m

Copying data to “cufftComplex” data struct?

丶灬走出姿态 提交于 2019-11-26 14:46:55
问题 I have data stored as arrays of floats (single precision). I have one array for my real data, and one array for my complex data, which I use as the input to FFTs. I need to copy this data into the cufftComplex data type if I want to use the CUDA cufft library. From nVidia: " cufftComplex is a single‐precision, floating‐point complex data type that consists of interleaved real and imaginary components." Data to be operated on by cufft is stored in arrays of cufftComplex . How do I quickly copy

memcpy vs assignment in C

谁说胖子不能爱 提交于 2019-11-26 14:06:35
问题 Under what circumstances should I expect memcpys to outperform assignments on modern INTEL/AMD hardware? I am using GCC 4.2.x on a 32 bit Intel platform (but am interested in 64 bit as well). 回答1: You should never expect them outperform assignments. The reason is, the compiler will use memcpy anyway when it thinks it would be faster (if you use optimize flags). If not and if the structure is reasonable small that it fits into registers, direct register manipulation could be used which wouldn

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

那年仲夏 提交于 2019-11-26 13:06:19
问题 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 ? 回答1: 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