memcpy

How can I copy unmanaged data in C# and how fast is it?

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have two unmanaged pointers in the form of IntPtr and want to copy data between them. How can I do this? I know the method Marshal.Copy , but it can only copy between unmanaged and managed. And the second part: Is copying unmanaged data from C# slower than doing it in unmanaged C/C++ using memcpy? Edit: I would be especially interested in a platform independet implementation. 回答1: You can use the win32 memcpy function via P-Invoke. [DllImport("msvcrt.dll", SetLastError = false)] static extern IntPtr memcpy(IntPtr dest, IntPtr src, int

How do I define and initialize an array of strings inside of a struct? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How do I create an array of strings in C? 14 answers typedef struct mobiltelefon { char herstellername[HLEN]; double displaydiagonale; aufloesung_t aufloesung; char standards[NUMBER_OF_STRINGS][STRINGLENGTH+1] = {"GPRS", "EDGE", "HSDPA", "HSUPA", "HSPA", "LTE"}; } telefon_t; I keep getting an error expected ; at the end of declaration list . 回答1: Change char (*standards[6])[5] = {{"GPRS"}, {"EDGE"}, {"HSDPA"}, {"HSUPA"}, {"HSPA"}, {"LTE"}}; to char standards[6][6] = {{"GPRS"}, {"EDGE"}, {"HSDPA"}, {

Optimal Base-10 only itoa() function? [closed]

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In 20+ years programming in C I've used a base other than 10 once, so when I found my trusty MSVC's _itoa() missing in another environment, I set out to write one that only does base 10, and puts the destination buffer argument, pointing to the storage returned by the function, on the left, instead of on the right, like all of the string functions in the C Standard Library. I believe this code is also thread-safe. Is there a faster way to do this? I was also going to ask about correctness, but I believe the included test code proves it works

PYTHON - Ctypes : OSError: exception: access violation writing 0xFFFFFFFFFA1C001B

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here is a code for writing values to memory using memory mapping. When I try to run the code, I get the error "File "MMF.py", line 26, in memcpy(pBuf, szMsg, len(szMsg)) OSError: exception: access violation writing 0xFFFFFFFFFA1C001B" import msvcrt, mmap import ctypes from ctypes import * FILE_MAP_ALL_ACCESS = 0x04 INVALID_HANDLE_VALUE = 0xFFFFFFFF SHMEMSIZE = 256 PAGE_READWRITE = 0x04 szName = ctypes.c_wchar_p("MyFileMappingObject") szMsg = "Message from Python(ctypes) process" hMapObject = windll.kernel32.CreateFileMappingA(INVALID_HANDLE

In what platform memmove and memcpy can have significant performance difference?

匿名 (未验证) 提交于 2019-12-03 00:50:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I understand that memmove and memcpy difference is that memmove handles the memory overlap case. I have checked the implementation in libgcc and got this article [memcpy performance] from the intel website. In libgcc, the memmove is similar to memcpy , both just go though one byte and byte, so the performance should be almost same even after optimization. Someone has measured this and got this article memcopy, memmove, and Speed over Safety . Even I don't think the memmove can be faster than memcpy , but there should be no big difference at

mem系列与str系列函数了解

匿名 (未验证) 提交于 2019-12-03 00:28:02
系列函数通常处理内存内容,而Str通常处理字符串,这俩个家族系列函数经常会使用,在网上搜集了一些资料进行了整理,方便自己以后查阅,下面介绍了memcpy,strcpy,strncpy,memmove,memcmp,strcmp,strcat,strstr,strtok等函数: 函数原型 :void *memcpy(void *dest, const void *src,size_t n); 函数功能 :内存拷贝;将src指向内存地址的连续N个指针位置的内容拷贝至dest指针指向的位置 函数返回 :无 参数说明 : dest ― 目的内存空间指针 src ― 源内存 n ― 拷贝指针位置个数 # include <memory> include <iostream> include < string > void main() { char * src = “Hello Frankie World !”; char * dest = new char [ 50 ]; memset (dest, 0 , 50 ); memcpy (dest,src, 7 ); std :: cout <<”dset值为:”<< std ::endl; Out(dest); } 函数原型 :void * memccpy(void *dest, void *src, unsigned char c,

strcpy、memcpy和memset之间的区别

匿名 (未验证) 提交于 2019-12-03 00:22:01
今天刷题时遇到了这个问题,记录一下。 strcpy 比较简单,就是拷贝字符串,遇到'\0'时结束拷贝 。 memcpy 用来做内存拷贝,可以拷贝任何数据类型的对象并指定拷贝数据的长度:char a[100],b[50]; memcpy(b, a, sizeof(b)); 总结一下: strcpy和memcpy主要有以下3方面的区别。 复制的内容不同。strcpy只能复制字符串,而memcpy可以复制任意内容,例如字符数组、整型、结构体、类等。 复制的方法不同。strcpy不需要指定长度,它遇到字符串结束符"\0"便结束。memcpy则是根据其第3个参数决定复制的长度。 用途不同。通常在复制字符串时用strcpy,而需要复制其他类型数据时则一般用memcpy。 //注意:如果用的是sizeof(a),则会造成内存泄露。 比较复杂点的是 memset ,用来对一段内存空间全部设置为某个字符,一般用在对定义的字符串进行初始化为 ‘ ’或 ‘\0’,比如: char a[100];memset(a, '\0', sizeof(a)); 另外比较方便的是对结构体的操作, memset可以方便的清空一个结构类型的变量或数组: 比如有结构体struct sample_strcut stTest,一般清空结构体的话得用如下方式: struct sample_struct { char csName

智能指针的使用注意事项

匿名 (未验证) 提交于 2019-12-02 23:34:01
因为智能指针是通过引用计数的方式来进行判断何时进行析构的, 1)所以不要对含有智能指针的结构体进行memcpy,因为memcpy不会增加引用计数,从而导致错误; 2)不要对智能指针本身进行memcpy,同样因为memcpy不会增加引用计数,从而导致错误; 3)如果结构体中放有智能指针,则注意不要使用memecpy等防止进行内存拷贝,如果要发生内存拷贝,就应该放普通指针; 结构体设计时就要考虑到该结构体被谁使用,有几份等因素,来决定结构体中是否需要放结构体对象还是结构体指针,另外结构体中放指针时,尽量使用普通指针,便于维护; 结构体中,智能指针和普通指针可以并存;但是联合体中就不能放智能指针了,因为智能指针是模板类,大小不是四个字节,不好估计其大小。 文章来源: https://blog.csdn.net/dbdxnuliba/article/details/90286748

Problem when copying memory

旧街凉风 提交于 2019-12-02 23:33:32
问题 So there is a problem I am headbanging over two nights in a row: (tuple1 and tuple2 are void pointers passed to this function) char *data; data = (char*) calloc (76, 1); memcpy(data, tuple1, 32); memcpy(data+32, tuple2, 44); The idea is to allocate memory equal to the sum of the sizes of tuple1 and tuple2 ( tuple1 is 32 bytes and tuple2 is 44) and then copy the 32 bytes of tuple1 and paste them at the address of data and after that copy the 44 bytes of tuple2 and paste them 32 bytes after the

C语言 memcpy的实现

匿名 (未验证) 提交于 2019-12-02 23:32:01
#include<stdio.h> #include<stdlib.h> void mymemcpy(char *str1, char *str2, int k) { int i; for (i = 0; i < k; i++,str1++,str2++) { *str1 = *str2; } } int main() { int k = 3; char str1[]=" "; char* str2 = "ancde"; mymemcpy(str1, str2, k); printf("%s", str1); system("pause"); return 0; }