memcpy

memcpy with startIndex?

走远了吗. 提交于 2019-12-03 06:32:28
问题 I wish to copy content of specific length from one buffer to another from a specific starting point. I checked memcpy() but it takes only the length of content to be copied while I want to specify the starting index too. Is there any function which can do this or is there any good approach to do it with the existing memcpy function? 回答1: I always prefer the syntax memcpy( &dst[dstIdx], &src[srcIdx], numElementsToCopy * sizeof( Element ) ); 回答2: Just add the offset you want to the address of

c++ memcpy return value

时光毁灭记忆、已成空白 提交于 2019-12-03 04:19:37
according to http://en.cppreference.com/w/cpp/string/byte/memcpy c++'s memcpy takes three parameters: destination, source and size/bytes. it also returns a pointer. why is that so? aren't the parameters enough to input and copy data. or am i misunderstanding something? the examples don't use the return value If a function has nothing specific to return, it is often customary to return one of the input parameters (the one that is seen as the primary one). Doing this allows you to use "chained" function calls in expressions. For example, you can do char buffer[1024]; strcat(strcpy(buffer, "Hello

考试总结 模拟96

末鹿安然 提交于 2019-12-03 04:02:18
可能是打球过度劳累?真的很困的一场考试。 考试状态不再谈了。 需要记住的 copy一个区间的时候,不要用memcpy!! 这几场考试的数据都很水,T2最后发现写了一个memcpy的5e5的数组,结果TLE20,居然没有阶乘暴力分高!! 然后把memcpy写成for循环,就搞到了70。。。。 T1「慢速乘」 简单化式子,贡献分别计算,i,j,-1 然后考试最后自己yy了一个慢速乘, 写的不够简洁,其实把快速幂的×改成+就好了 T2「贪心」「倍增」 和上一次的T2感觉是差不多的,第一眼的感觉确实很不可做,然后多看一会就会yy出一些性质, 然后打表证明它的对的就十分开心 性质1:由于每多一对点贡献必定增加,那么只要从前往后只要不超过m就放,就会最少 性质2:对于每个区间,贡献最大的情况是最大a的对应最大的b 如果把贡献换成(a-b)^2,那么最大的贡献是最大的a对应最小的b(算法进阶0x06倍增) 现在每次chk就是O(len log {len})的了 对于每一个左端点,我们去倍增寻找它的右端点,算法流程是: 初始p=1,r=l, 1.如果chk(left,r+p)==1合法,那么就让r+=p,p<<=1; 2,否则让p<<=1; 3.while结束条件是p==0 T3 各种乱搞都能拿20+ 然而我爆0了。。。。 来源: https://www.cnblogs.com/casun547

strcpy()/strncpy() crashes on structure member with extra space when optimization is turned on on Unix?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When writing a project, I ran into a strange issue. This is the minimal code I managed to write to recreate the issue. I am intentionally storing an actual string in the place of something else, with enough space allocated. // #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <stddef.h> // For offsetof() typedef struct _pack{ // The type of `c` doesn't matter as long as it's inside of a struct. int64_t c; } pack; int main(){ pack *p; char str[9] = "aaaaaaaa"; // Input size_t len = offsetof(pack, c) +

Memcpy vs Memmove - Debug vs Release

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got really strange behavior for my x64 multithreading application. The execution time in debug mode is faster than in release mode. I break the problem down and found the issue: The debug modus optimize (!Note optimition is off!) the memcpy to memmove, which peforms faster. The release mode use still memcpy (!note optimition is on). This problem slows down my multithreading app in release mode. :( Anyone any idea? #include <time.h> #include <iostream> #define T_SIZE 1024*1024*2 int main() { clock_t start, end; char data[T_SIZE]; char store

Why isn't memcpy guaranteed to be safe for non-POD types?

匿名 (未验证) 提交于 2019-12-03 02:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I read about this paragraph from a few questions posted on SO. I can't quite figure out why memcpy isn't guaranteed to be safe for a non-POD type. My understanding is that memcpy is just a bit-wise copy. Below is a quote from standard For any object (other than a base-class subobject) of POD type T , whether or not the object holds a valid value of type T , the underlying bytes (1.7) making up the object can be copied into an array of char or unsigned char .41) If the content of the array of char or unsigned char is copied back

memcpy函数的用法以及实现一个memcpy函数

不羁的心 提交于 2019-12-03 02:33:21
memcpy的用法 在项目中经常用到 memcpy 来实现内存的拷贝工作,如下代码片段 memcpy( pData, m_pSaveData_C, iSize * sizeof( unsigned short ) ); memcpy 的函数原型为: void * memcpy ( void * destination, const void * source, size_t num ); memcpy函数的功能是从源内存地址的起始位置开始拷贝若干个 字节 到目标内存地址中,即从源source中拷贝num个 字节 到目标destin中。 示例代码 int main() { vector<int> vec; vector<int> vec1; vec.push_back(10); vec.push_back(100); vec1.resize(vec.size()); memcpy(vec1.data(),vec.data(),vec.size() * sizeof(int)); for (vector<int>::iterator it = vec1.begin();it != vec1.end();it++) { cout << *it; } char myname[] = "Pierre dee Fermat"; memcpy(person.name,myname,strlen

gdb reverse debugging fails with “Process record does not support instruction 0xf0d at address”

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i started to try reverse debugging with gdb 7, followin the tutorial: http://www.sourceware.org/gdb/wiki/ProcessRecord/Tutorial and I thought, great! Then I started to debug a real program which gives an error at the end. So I run it with gdb, and I put a breakpoint just before the place I think the error appears. Then I type "record" in order to start to recrd actions for future reverse-debugging. But after some steps I get Process record doesn't support instruction 0xf0d at address 0x2aaaab4c4b4e. Process record: failed to record execution

Getting GCC to compile without inserting call to memcpy

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 reference to memcpy: $ powerpc-440-eabi-nm output.o | grep