memcpy

Undefined reference to memcpy_s

ⅰ亾dé卋堺 提交于 2019-12-07 08:35:27
问题 I'm trying to fix an undefined reference to memcpy_s() error. I've included string.h in my file and the memcpy() function works okay, and I've also tried including memory.h . I'm on x64 Windows 7 and using gcc 4.8.1 to compile. #include <stdlib.h> #include <stdio.h> #include <string.h> void doMemCopy(char* buf, size_t buf_size, char* in, int chr) { memcpy_s(buf, buf_size, in, chr); } memory for buf has been allocated in the main function, which calls doMemCpy(buf, 64, in, bytes) . in is a

Can I use memcpy to write to multiple adjacent Standard Layout sub-objects?

99封情书 提交于 2019-12-07 02:59:39
问题 Disclaimer: This is trying to drill down on a larger problem, so please don't get hung up with whether the example makes any sense in practice. And, yes, if you want to copy objects, please use / provide the copy-constructor. (But note how even the example does not copy a whole object; it tries to blit some memory over a few adjacent(Q.2) integers.) Given a C++ Standard Layout struct , can I use memcpy to write to multiple (adjacent) sub-objects at once? Complete example: ( https://ideone.com

简单排序算法之插入排序、选择排序和冒泡排序

穿精又带淫゛_ 提交于 2019-12-06 22:27:02
倒也不是临时起意,被问了冒泡排序,我竟然……忘了,好吧,时隔多年重见冒泡,好久不见 甚是想念; 于是乎就写了下代码,顺便重温了两个简单的排序算法:插入排序和选择排序; 作为一个开头,之后有机会就把其它相关排序也总结下,不得不说,真的好生疏/(ㄒoㄒ)/~~ 简单排序算法之插入排序、选择排序和冒泡排序 插入排序: 插入排序是从无序区里依次拿到元素放到有序区里合适的位置; 选择排序; 选择排序是每次将无序区里的最小值放到有序区里的最后一个位置; 冒泡排序; 冒泡排序是每次循环将最大的数“冒泡”到最上边; 有了这几个简单的描述,接下来让我们一个一个来看下; 1.插入排序: 插入排序是从无序区里依次拿到元素放到有序区里合适的位置; 1.1插入排序的理解: 可以将原来的数组看成两个区,分别用两个数组来表示,一个有序区,一个无序区; 有序区起始包含一个元素,即原数组的位置0所对应的元素; 无需区则包含剩余的所有元素; 我们遍历无需区元素,然后与有序区(从末尾位置)逐个进行比较,因为有序区有序,所以当找到满足比较大小的要求时对应的位置,就是元素要插到有序区对应的位置; 为此,我们还需要遍历有序区,好让遍历无序区的元素在有序区中找到合适的位置; 遍历无序区对应算法的外循环; 遍历有序区,比较出无序元素的位置对应内循环; 1.2我们看下具体实现的代码: //插入排序 /*数组 数组长度

Microsoft SDL and memcpy deprecation

二次信任 提交于 2019-12-06 22:14:02
问题 As some of you may know, Microsoft banned memcpy() from their Security Development Lifecycle, replacing it with memcpy_s() . void *memcpy(void *dest, const void *src, size_t n); /* simplified signature */ errno_t memcpy_s(void *dst, size_t dstsize, const void *src, size_t n); So if your code used to be: if (in_len > dst_len) { /* error */ } memcpy(dst, src, in_len); it becomes: if (memcpy_s(dst, dst_len, src, src_len)) { /* error */ } Or, with truncation, memcpy(dst, src, min(in_len, dst_len)

Fast memcpy in C#

一曲冷凌霜 提交于 2019-12-06 15:58:12
问题 I want to write a C# method with prototype like this: void memcpy(byte[] dst, int dstOffset, byte[] src, int srcOffset, int len); I have 2 options for this method: 1. void memcpy(byte[] dst, int dstOffset, byte[] src, int srcOffset, int len) { for (int i = 0; i < len; i++) { dst[dstOffset + i] = src[srcOffset + i]; } } 2. void memcpy(byte[] dst, int dstOffset, byte[] src, int srcOffset, int len) { IntPtr intPtr = getIntPtr(dst, dstOffset); System.Runtime.InteropServices.Marshal.Copy(src,

Struct inheritance vs class inheritance in C++

我与影子孤独终老i 提交于 2019-12-06 05:49:03
问题 I just discovered from this Q/A that structs are inheritable in C++ but, is it a good practice, or is it preferable to use classes? In which cases is preferable and in which ones is not? I have never needed this, but now I have a bunch of messages of different types, but same longitude. I got them in binary in a char array, and I just copy them with memcpy to the struct to fill its fields (I don't know if it is even possible to do it with std::copy). I guess it would be great to be able to

memset// memcpy

蹲街弑〆低调 提交于 2019-12-06 05:13:01
ch只有最低的字节起作用 自己写的memcpy可能存在内存重叠问题,要特别注意 来源: https://www.cnblogs.com/focus-z/p/11963600.html

SIGBUS while doing memcpy from mmap ed buffer which is in RAM as identified by mincore

丶灬走出姿态 提交于 2019-12-05 21:45:18
I am mmapping a block as: mapAddr = mmap((void*) 0, curMapSize, PROT_NONE, MAP_LOCKED|MAP_SHARED, fd, curMapOffset); if this does not fail (mapAddr != MAP_FAILED) I query mincore as: err = mincore((char*) mapAddr, pageSize, &mincoreRet); to find out whether it is in RAM. In case it is in RAM (err == 0 && mincoreRet & 0x01) I mmap it again for reading as: copyAddr = mmap((void*) 0, curMapSize, PROT_READ, MAP_LOCKED|MAP_SHARED, fd, curMapOffset); and then I try to copy it out to my buffer as: memcpy(data, copyAddr, pageSize); everything works fine except in the last memcpy once in a while I get

Multithread Programming for memcpy

自闭症网瘾萝莉.ら 提交于 2019-12-05 18:21:48
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 mt_memcpy functions in the original main function? #define NUM_CPY_THREADS 4 HANDLE hCopyThreads[NUM

Undefined reference to memcpy_s

六月ゝ 毕业季﹏ 提交于 2019-12-05 17:59:21
I'm trying to fix an undefined reference to memcpy_s() error. I've included string.h in my file and the memcpy() function works okay, and I've also tried including memory.h . I'm on x64 Windows 7 and using gcc 4.8.1 to compile. #include <stdlib.h> #include <stdio.h> #include <string.h> void doMemCopy(char* buf, size_t buf_size, char* in, int chr) { memcpy_s(buf, buf_size, in, chr); } memory for buf has been allocated in the main function, which calls doMemCpy(buf, 64, in, bytes) . in is a string read from standard input Exact error from cmd terminal: undefined reference to "memcpy_s" collect2