memcpy

c++ use ifstream from memory

泪湿孤枕 提交于 2019-12-08 18:56:36
问题 I have some code that uses ifstream to read some data from a file and everything works. Now I wish, without modifying some code, read this data from a memory, actually I have a char * that contains the data... How can I put my char * data into a ifstream without reading effectively the file? 回答1: If the code that uses the ifstream& could be changed slightly to use an istream& then you could easily switch between ifstream and istringstream (for reading data from memory): void read_data(std:

memcpy/memset函数的c语言实现

核能气质少年 提交于 2019-12-08 17:24:44
1、memcpy 头文件:#include <string.h> 函数原型:void *memcpy(void *dest, const void *src, size_t n) 功能:将指针src指向的内存空间的n个字节复制到dest指针指向的内存空间 参数:src 为原内容内存的起始地址,dest为复制到目标地址的起始地址 返回值:目标dest内存的起始地址 注意:1、 内存空间不能够有重叠; 2、 memcpy对于需要复制的内容没有限制,因此用途更广; 3、很明确的是memcpy是将 n个字节, 虽然memcpy对复制的内容完全没有任何的限制,比如数组,结构体等特殊的结构,如果你想将整个结构体变量的内容复制到dest内存区,最好使用sizeof将要复制的内容的完整大小求出来赋值给n,以保持复制的完整性; c代码: void *memCpy(void *dest, const void *src, size_t n) { if (NULL == dest || NULL == src || n < 0) return NULL; char *tempDest = (char *)dest; char *tempSrc = (char *)src; while (n-- > 0) *tempDest++ = *tempSrc++; return dest; } 2、memset

C语言内存操作函数的实现

泪湿孤枕 提交于 2019-12-08 17:23:02
>memcpy: void *memcpy(void *dest,const void *source,size_t num); (1)函数memcpy从source的位置开始向后复制num个字节的数据到dest的内存位置。 (2)这个函数在遇到'\0'的时候并不会停下来。 (3)如果source和dest有任何的重叠,复制的结果都是未定义的。 void *my_memcpy(void *dest, const void *str, int size) { assert(dest); assert(str); assert(size > 0); while (size--){ *(char *)dest = *(char *)str; (char *)dest = (char *)dest + 1; (char *)str = (char *)str + 1; } return dest; } 适用于dest>source,如果dest<source就会内存从叠问题,从前往后拷贝时前一个会把后一个覆盖num个字节。这时就需要用到memmove。 >memmove: void *memmove (void *dest,const char *str,int size); (1)和memmove的差别就是memmove函数处理的源内存块的目标内存块是可以重叠的。 (2

How can I concatenate two structs type variables in c++? [closed]

给你一囗甜甜゛ 提交于 2019-12-08 15:38:03
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . I'e been trying for sometime to concatenate some struct (I defined) type variables into a bigger one. What I got is basically like this: I have a struct and two variables of type struct**. I declare a third one struct C and I want to concatenate A and B into C. What I tried is something like this

Is there a standard, strided version of memcpy?

吃可爱长大的小学妹 提交于 2019-12-08 15:00:47
问题 I have a column vector A which is 10 elements long. I have a matrix B which is 10 by 10. The memory storage for B is column major. I would like to overwrite the first row in B with the column vector A. Clearly, I can do: for ( int i=0; i < 10; i++ ) { B[0 + 10 * i] = A[i]; } where I've left the zero in 0 + 10 * i to highlight that B uses column-major storage (zero is the row-index). After some shenanigans in CUDA-land tonight, I had a thought that there might be a CPU function to perform a

Detours Hook memcpy Not Working

假如想象 提交于 2019-12-08 12:13:18
问题 I have programmed hook for memcpy but it only calls on the end of the program. Not each time, when was function called. Also the adresses are different. This is the hook: #include <windows.h> #include<iostream> #include "detours\detours.h" #pragma comment( lib, "msvcrt.lib" ) #pragma comment( lib, "detours.lib" ) //#pragma comment( lib, "detoured.lib" ) //int (WINAPI *Real_Send)(SOCKET s, const char *buf, int len, int flags) = send; //int WINAPI Mine_Send(SOCKET s, const char* buf, int len,

Concatenating two arrays of strings?

≯℡__Kan透↙ 提交于 2019-12-08 02:11:53
问题 I am new to the c world and I want to merge two arrays into one array, i have one idea how to do this, but it doesnt work :P char *s_one[] = { "Zorro", "Alex", "Celine" }; char *s_two[] = { "Zorro1", "Alex1"}; char *p = (char*)malloc((sizeof(s_one)+sizeof(s_two))*sizeof(char)); memcpy(p, s_one, sizeof(s_one)); memcpy(p + sizeof(s_one), s_two, sizeof(s_two)); //print out for (count = 0; count < sizeof(p); count++) printf("\narr[%d] = %c.", count, p[count]); the output is just some random

Multithread Programming for memcpy

不打扰是莪最后的温柔 提交于 2019-12-07 11:58:38
问题 I am doing an optimization task for memcpy function, I found this link here. How to increase performance of memcpy Since I'm not familiar with multithread programming, I don't know how to insert the codes below to the original main function? How to modify the codes in the original question into a multithread memcpy project? I mean, how to create a complete project for this multithread memcpy project. Where are the places for inserting the functions like startCopyThreads or stopCopyThreads or

C-基础:memcpy、memset、memmove、memcmp、memchr

流过昼夜 提交于 2019-12-07 09:19:27
一,原型 void * memcpy ( void * destination, const void * source, size_t num ); 功能: 将以source作为起始地址的数据复制num个字节到以destination为起始地址的数据中,不支持destination和source重叠的情况。函数返回destination指针。 void * memcpy ( void * destination,constvoid* source,size_t num ) {    char * pdes =( char * )destination;    char * psrc =( char * )source;   assert(destination !=NULL && source !=NULL && num> 0 );    while (num-- )      *pdes++=*psrc++ ;    return destination; } void * memmove ( void * destination, const void * source, size_t num ); 功能: 将以source作为起始地址的数据的num个字节移动到以destination为起始地址的数据中,支持destination和source重叠的情况

c语言| |memcpy函数与memmove函数

会有一股神秘感。 提交于 2019-12-07 09:18:16
memcpy和memmove函数 memcpy函数 1.源函数 void * memcpy ( void * dest , const void * src , size_t n ) 2.作用 (小编自己的理解)内存拷贝。从src内存空间移动n个元素,将其赋值给dest的内存中,从内存中第一个地址所指向的数据开始赋值,直到赋值n个数据,该函数调用结束,同时返回dest,即返回被赋值的内存的起始位置。返回dest的意义是可是增加链接属性。 memcpy函数实现 : (my_memcpy) 原谅小编没有找到源代码 #include <assert.h> //包含assert函数的头文件 #define my_type int //自己定义要进行内存赋值的数据类型 ​ my_type * my_memcpy ( my_table * dest , const my_type * src , size_t n ) { my_type * start = dest ; //用于返回dest的初始地址,使该函数具有链接属性 assert ( dest != NULL ); //断言dest与src不是空地址 assert ( src != NULL ); while ( n -- ) { * dest ++ = * src ++ ; } return start ; }