memcpy

atoi on a character array with lots of integers

北城以北 提交于 2019-12-01 10:39:15
问题 I have a code in which the character array is populated by integers (converted to char arrays), and read by another function which reconverts it back to integers. I have used the following function to get the conversion to char array: char data[64]; int a = 10; std::string str = boost::lexical_cast<std::string>(a); memcpy(data + 8*k,str.c_str(),sizeof(str.c_str())); //k varies from 0 to 7 and the reconversion back to characters is done using: char temp[8]; memcpy(temp,data+8*k,8); int a =

glMapBuffer undeclared in OpenGL-ES 2.0

拈花ヽ惹草 提交于 2019-12-01 08:32:15
I am doing Opengl-es 2.0 in ununtu 10.10 through the use of kronos and pvrsdk .Now code #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> ==========|||||||||||||||||||||||||||||||||||=================== GLfloat *pData = glMapBufferOES (GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); for(i=0; i<triNum[surfnum]; ++i,pData+=9) { memcpy(pData, triArray[surfnum][i].pt1, 3*sizeof(GLfloat)); memcpy(pData+3, triArray[surfnum][i].pt2, 3*sizeof(GLfloat)); memcpy(pData+6, triArray[surfnum][i].pt3, 3*sizeof(GLfloat)); } glUnmapBufferOES (GL_ARRAY_BUFFER); Error : src/Hello.cpp: In function 'int main(int, char**)':

strcpy和memcpy的区别(转)

你。 提交于 2019-12-01 07:22:15
strcpy和memcpy都是标准C库函数,它们有下面的特点。 strcpy提供了字符串的复制。即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符。 已知strcpy函数的原型是:char* strcpy(char* dest, const char* src); memcpy提供了一般内存的复制。即memcpy对于需要复制的内容没有限制,因此用途更广。 void *memcpy( void * dest , const void * src , size_t count ); char * strcpy ( char * dest, const char * src) // 实现src到dest的复制 {    if ((src == NULL) || (dest == NULL)) //判断参数src和dest的有效性   {        return NULL;   }    char *strdest = dest; //保存目标字符串的首地址    while ((*strDest++ = *strSrc++)!= '\0' ); //把src字符串的内容复制到dest下    return strdest; } void * memcpy ( void *memTo, const void *memFrom, size_t size)

What are the changes, if any, to the memcpy lifetime initalization rules in the new standard?

好久不见. 提交于 2019-12-01 06:53:47
问题 As far as I am aware, memcpy into uninitialized storage cannot safely be used to create an copy of the source object. However, in this thread from last year on the open-std WG21 "ub" list, a participant refers to the new memcpy lifetime-initiation rules : This doesn’t seem to rise to the level of a bug report, but it might be relevant to the new memcpy lifetime-initiation rules. Will they ascribe some static type to the source and destination bytes? Based on the context of the question and

glMapBuffer undeclared in OpenGL-ES 2.0

女生的网名这么多〃 提交于 2019-12-01 06:46:21
问题 I am doing Opengl-es 2.0 in ununtu 10.10 through the use of kronos and pvrsdk .Now code #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> ==========|||||||||||||||||||||||||||||||||||=================== GLfloat *pData = glMapBufferOES (GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); for(i=0; i<triNum[surfnum]; ++i,pData+=9) { memcpy(pData, triArray[surfnum][i].pt1, 3*sizeof(GLfloat)); memcpy(pData+3, triArray[surfnum][i].pt2, 3*sizeof(GLfloat)); memcpy(pData+6, triArray[surfnum][i].pt3, 3*sizeof(GLfloat)

Dereferencing function pointers in C to access CODE memory

橙三吉。 提交于 2019-11-30 20:21:41
We are dealing with C here. I'm just had this idea, wondering if it is possible to access the point in memory where a function is stored, say foo and copying the contents of the function to another point in memory. Specifically, I'm trying to get the following to work: #include <stdlib.h> #include <stdio.h> #include <string.h> void foo(){ printf("Hello World"); } int main(){ void (*bar)(void) = malloc(sizeof foo); memcpy(&bar, &foo, sizeof foo); bar(); return 0; } But running it gives a bus error: Bus error: 10 . I'm trying to copy over the contents of function foo into a space of memory bar

GCC with -fno-builtin does not seem to work

不羁岁月 提交于 2019-11-30 20:08:35
I would like to compare the GCC builtin function memcpy versus the one one from libc. However, all iterations of -fno-builtin or -fno-builtin-memcpy seem to be ignored. //g++ -O3 foo.cpp -S or //g++ -O3 -fno-builtin foo.cpp -S #include <string.h> int main() { volatile int n = 1000; //int n = 1000; float *x = new float[1000]; float *y = new float[1000]; memcpy(y,x,sizeof(float)*n); //__builtin_memcpy(y,x,sizeof(float)*n); } What I have found is that if n in the source code above is not volatile then it inlines built-in code. However, when n is made volatile then it calls the function __memcpy

C++对数组进行复制

时间秒杀一切 提交于 2019-11-30 15:12:26
C++ 风格的复制操作 使用STL中的copy算法 int a[] = {1,2,3,4,5}; int b[5]; std::copy(std::begin(a),std::end(a),std::begin(b)); for(auto e:b) cout<<e<<" "; // 输出 1,2,3,4,5 上述程序中,copy算法将数组a区间中的数复制到以begin(b)开始的区间中去. 使用array容器 (C++11) std::array<int,5> arr = {1,2,3,4,5}; std::array<int,5> copy; copy = arr; // 将arr中的元素复制到copy中 arr[0] = 100; for(auto e:copy) cout<<e<<" "; //输出 1,2,3,4,5 C 风格的复制操作 使用memcpy() int arr[] = {1,2,3,4,5}; int copy[5]; int len = sizeof(arr) / sizeof(arr[0]); memcpy(copy,arr,len*sizeof(int)); // 输出 1,2,3,4,5 for(auto e:copy) cout<<e<<" "; 注意:memcpy()函数的第三个参数表示的是要复制的字节数,而不是要复制的元素数目。至于这样做的原因

C memcpy in reverse

淺唱寂寞╮ 提交于 2019-11-30 14:55:48
问题 I am working with audio data. I'd like to play the sample file in reverse. The data is stored as unsigned ints and packed nice and tight. Is there a way to call memcpy that will copy in reverse order. i.e. if I had 1,2,3,4 stored in an array, could I call memcpy and magically reverse them so I get 4,3,2,1. 回答1: This works for copying int s in reverse: void reverse_intcpy(int *restrict dst, const int *restrict src, size_t n) { size_t i; for (i=0; i < n; ++i) dst[n-1-i] = src[i]; } Just like

How to split array into two arrays in C

主宰稳场 提交于 2019-11-30 14:18:38
Say i have an array in C int array[6] = {1,2,3,4,5,6} how could I split this into {1,2,3} and {4,5,6} Would this be possible using memcpy? Thank You, nonono Sure. The straightforward solution is to allocate two new arrays using malloc and then using memcpy to copy the data into the two arrays. int array[6] = {1,2,3,4,5,6} int *firstHalf = malloc(3 * sizeof(int)); if (!firstHalf) { /* handle error */ } int *secondHalf = malloc(3 * sizeof(int)); if (!secondHalf) { /* handle error */ } memcpy(firstHalf, array, 3 * sizeof(int)); memcpy(secondHalf, array + 3, 3 * sizeof(int)); However, in case the