memcpy

Concatenate with memcpy

帅比萌擦擦* 提交于 2019-12-10 17:31:38
问题 I'm trying to add two strings together using memcpy. The first memcpy does contain the data, I require. The second one does not however add on. Any idea why? if (strlen(g->db_cmd) < MAX_DB_CMDS ) { memcpy(&g->db_cmd[strlen(g->db_cmd)],l->db.param_value.val,strlen(l->db.param_value.val)); memcpy(&g->db_cmd[strlen(g->db_cmd)],l->del_const,strlen(l->del_const)); g->cmd_ctr++; } 回答1: size_t len = strlen(l->db.param_value.val); memcpy(g->db_cmd, l->db.param_value.val, len); memcpy(g->db_cmd + len,

Hint to compiler that it can use aligned memcpy

主宰稳场 提交于 2019-12-10 16:17:39
问题 I have a struct consisting of seven __m256 values, which is stored 32-byte aligned in memory. typedef struct { __m256 xl,xh; __m256 yl,yh; __m256 zl,zh; __m256i co; } bloxset8_t; I achieve the 32-byte alignment by using the posix_memalign() function for dynamically allocated data, or using the (aligned(32)) attribute for statically allocated data. The alignment is fine, but when I use two pointers to such a struct, and pass them as destination and source for memcpy() then the compiler decides

is it possible to do memcpy in bits instead of bytes?

青春壹個敷衍的年華 提交于 2019-12-10 14:18:10
问题 I would like to know is it possible to do memcpy by bits instead of bytes ? I am writing a C code for Ethernet frame with VLAN tagging, in which I need to fill different values for VLAN header attributes (PCP-3bits,DEI-1bit,VID-12bits). How can I do memcpy to those bits, or any other possibility to fill values to those attributes in bits. Thanks in advance ! 回答1: No. Bits are not addressable (meaning that it is not possible to read them and only them directly from memory. They have no address

Is it safe to memcpy to a dynamic storage struct?

。_饼干妹妹 提交于 2019-12-10 13:39:37
问题 Context: I was reviewing some code that receives data from an IO descriptor into a character buffer, does some control on it and then use part of the received buffer to populate a struct, and suddenly wondered whether a strict aliasing rule violation could be involved. Here is a simplified version #define BFSZ 1024 struct Elt { int id; ... }; unsigned char buffer[BFSZ]; int sz = read(fd, buffer, sizeof(buffer)); // correctness control omitted for brievety // search the beginning of struct

Swift: how add offset to memcpy(…)

丶灬走出姿态 提交于 2019-12-10 13:04:52
问题 How to add offset for array for memcpy(...) invocation? I have array of String : var source = ["a","b","c","d"] var dest = [String](count:n, repeatedValue: "") memcpy(&dest, source, UInt(2 * sizeof(String)) This copy ["a","b"] to dest. I'ts obvious. How can i copy ["b", "c"] ? 回答1: Do not use memcpy or other low-level "C" operators on objects. That will not work for many reasons. Use the slice operator: var source = ["a","b","c","d"] var dest = Array(source[1...2]) println("dest: \(dest)")

Explanation of memcpy memmove GLIBC_2.14/2.2.5

两盒软妹~` 提交于 2019-12-09 16:09:42
问题 My issue originated with a shared library I was given without the option to recompile the library. The error stated undefined reference to memcpy@GLIBC_2.14 . The version of GLIBC on my machine was 2.12. I have seen fixes people have done online using the line __asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); The fix I made was using a hex editor to change the reference of 2.14 to GLIBC_2.2.5. When executing the command readelf -V lib_name.so , the outputs changed from: 0x0060 Name: GLIBC_2.14

memcpy和memmove使用区别

余生长醉 提交于 2019-12-09 15:11:13
memcpy函数原型 void * memcpy ( void * dest , const void * src , size_t n ) ; man手册描述:memcpy()函数从内存区域src复制n个字节到内存区域dest。内存区域不能重叠。如果内存区域重复使用memmove memcpy实现 void * memcpy ( void * dest , const void * src , size_t n ) { char * dp = dest ; const char * sp = src ; while ( n -- ) * dp ++ = * sp ++ ; return dest ; } memmove函数原型 void * memmove ( void * dest , const void * src , size_t n ) ; man手册描述:memmove()函数将n个字节从内存区域src复制到内存区域dest 首先将字节复制到不重叠的src或dest的临时数组中,然后将这些字节从临时数组复制到dest。 memmove实现 ```handlebars void * memmove ( void * dest , const void * src , size_t n ) { unsigned char tmp [ n ] ; memcpy ( tmp

atoi,itoa,strcpy, strcmp,strcpy, strcpy_s, memc...

不问归期 提交于 2019-12-09 10:30:51
strcpy()、strlen()、memcpy()、memmove()、memset()的实现 strcpy(), 字符串拷贝. char * strcpy( char * strDest, const char * strSrc) { assert((strDest != NULL) && (strSrc != NULL)); char * address = strDest; while ( ( * strDest ++ = * strSrc ++ ) != ' \0 ' ) NULL ; return address ; } strlen, 第一种方法: int strlen( const char *str) { assert(str != NULL); int len = 0; while ((*str++) != '\0' ) len++; return len; } 第二种方法: int strlen( const char *str) { assert(str != NULL); const char *p = str; while ((*p++) != '\0' ); return p - str - 1; } 第三种方法: int strlen( const char * str) { if (str[0] == '\0' ) return 0; else

C: memcpy speed on dynamically allocated arrays

空扰寡人 提交于 2019-12-09 08:28:48
问题 I need help with the performance of the following code. It does a memcpy on two dynamically allocated arrays of arbitrary size: int main() { double *a, *b; unsigned n = 10000000, i; a = malloc(n*sizeof(double)); b = malloc(n*sizeof(double)); for(i=0; i<n; i++) { a[i] = 1.0; /* b[i] = 0.0; */ } tic(); bzero(b, n*sizeof(double)); toc("bzero1"); tic(); bzero(b, n*sizeof(double)); toc("bzero2"); tic(); memcpy(b, a, n*sizeof(double)); toc("memcpy"); } tic/toc measure the execution time. On my

Is the std::array bit compatible with the old C array?

混江龙づ霸主 提交于 2019-12-09 07:30:34
问题 Is the underlying bit representation for an std::array<T,N> v and a T u[N] the same? In other words, is it safe to copy N*sizeof(T) bytes from one to the other? (Either through reinterpret_cast or memcpy .) Edit: For clarification, the emphasis is on same bit representation and reinterpret_cast . For example, let's suppose I have these two classes over some trivially copyable type T , for some N : struct VecNew { std::array<T,N> v; }; struct VecOld { T v[N]; }; And there is the legacy