memcpy

Explanation of memcpy memmove GLIBC_2.14/2.2.5

别等时光非礼了梦想. 提交于 2019-12-04 03:11:45
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 Flags: none Version 6 ...... 0x0080 Name: GLIBC_2.2.5 Flags: none Version 4 to: 0x0060 Name: GLIBC_2.2.5

Difference between memcpy and copy by assignment

那年仲夏 提交于 2019-12-03 20:19:56
Struct A { uint16_t len; uint8_t cnt; uint8_t unit; uint32_t seq; }; This struct A is serialized into a char * buf. If I want to deserialize the individual values eg: uint16_t len = 0; memcpy(&len, buf, sizeof(len)); or I can just do uint16_t len = (uint16_t) buf; Which one is better or are both the same? Also to deserialize the whole struct, if I just do A tmp; memcpy(&tmp, buf, sizeof(A)); Would this work fine or should I be worried about padding etc from the compiler? When the data is copied into char[] buffer, it may not be properly aligned in memory for access as multi-byte types. Copying

Fast ARM NEON memcpy

谁说我不能喝 提交于 2019-12-03 16:34:30
I want to copy an image on an ARMv7 core. The naive implementation is to call memcpy per line. for(i = 0; i < h; i++) { memcpy(d, s, w); s += sp; d += dp; } I know that the following d, dp, s, sp, w are all 32-byte aligned, so my next (still quite naive) implementation was along the lines of for (int i = 0; i < h; i++) { uint8_t* dst = d; const uint8_t* src = s; int remaining = w; asm volatile ( "1: \n" "subs %[rem], %[rem], #32 \n" "vld1.u8 {d0, d1, d2, d3}, [%[src],:256]! \n" "vst1.u8 {d0, d1, d2, d3}, [%[dst],:256]! \n" "bgt 1b \n" : [dst]"+r"(dst), [src]"+r"(src), [rem]"+r"(remaining) : :

C memcpy() a function

久未见 提交于 2019-12-03 16:03:09
Is there any method to calculate size of a function? I have a pointer to a function and I have to copy entire function using memcpy. I have to malloc some space and know 3rd parameter of memcpy - size. I know that sizeof(function) doesn't work. Do you have any suggestions? Functions are not first class objects in C. Which means they can't be passed to another function, they can't be returned from a function, and they can't be copied into another part of memory. A function pointer though can satisfy all of this, and is a first class object. A function pointer is just a memory address and it

memcpy vs assignment in C — should be memmove?

走远了吗. 提交于 2019-12-03 12:19:06
As pointed out in an answer to this question , the compiler (in this case gcc-4.1.2, yes it's old, no I can't change it) can replace struct assignments with memcpy where it thinks it is appropriate. I'm running some code under valgrind and got a warning about memcpy source/destination overlap. When I look at the code, I see this (paraphrasing): struct outer { struct inner i; // lots of other stuff }; struct inner { int x; // lots of other stuff }; void frob(struct inner* i, struct outer* o) { o->i = *i; } int main() { struct outer o; // assign a bunch of fields in o->i... frob(&o.i, o); return

Fastest de-interleave operation in C?

♀尐吖头ヾ 提交于 2019-12-03 11:34:05
I have a pointer to an array of bytes mixed that contains the interleaved bytes of two distinct arrays array1 and array2 . Say mixed looks something like this: a1b2c3d4... What I need to do is de-interleave the bytes so I get array1 = abcd... and array2 = 1234... . I know the length of mixed ahead of time, and the lengths of array1 and array2 are equivalent, both equal to mixed / 2 . Here is my current implementation ( array1 and array2 are already allocated): int i, j; int mixedLength_2 = mixedLength / 2; for (i = 0, j = 0; i < mixedLength_2; i++, j += 2) { array1[i] = mixed[j]; array2[i] =

Performance of list(…).insert(…)

北战南征 提交于 2019-12-03 10:59:47
I thought about the following question about computer's architecture. Suppose I do in Python from bisect import bisect index = bisect(x, a) # O(log n) (also, shouldn't it be a standard list function?) x.insert(index, a) # O(1) + memcpy() which takes log n , plus, if I correctly understand it, a memory copy operation for x[index:] . Now I read recently that the bottleneck is usually in the communication between processor and the memory so the memory copy could be done by RAM quite fast. Is it how that works? Stephan202 Python is a language. Multiple implementations exist , and they may have

ARM memcpy and alignment

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using the NEON memory copy with preload implementation from the ARM website with the Windows Embedded Compact 7 ARM assembler on a Cortex-A8 processor. I notice that I get datatype misalignment exceptions when I provide that function with non word aligned values For example: ; NEON memory copy with preload ALIGN LEAF_ENTRY NEONCopyPLD PLD [r1, #0xC0] VLDM r1!,{d0-d7} ;datatype misalignment VSTM r0!,{d0-d7} SUBS r2,r2,#0x40 MOV R0, #0 MOV PC, LR ENTRY_END size_t size = /* arbitrary */; size_t offset = 1; char* src = new char[ size +

Efficient way to copy strided data (to and from a CUDA Device)?

眉间皱痕 提交于 2019-12-03 08:51:39
Is there a possibility to copy data strided by a constant (or even non-constant) value to and from the CUDA device efficiently? I want to diagonalize a large symmetric matrix. Using the jacobi algorithm there is a bunch of operations using two rows and two columns within each iteration. Since the Matrix itself is too big to be copied to the device entirely i am looking for a way to copy the two rows and columns to the device. It would be nice to use the triangular matrix form to store the data but additional downsides like non-constant row-length [not that Kind of a Problem] non-constant

Memcpy, string and terminator

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have to write a function that fills a char* buffer for an assigned length with the content of a string. If the string is too long, I just have to cut it. The buffer is not allocated by me but by the user of my function. I tried something like this: int writebuff(char* buffer, int length){ string text="123456789012345"; memcpy(buffer, text.c_str(),length); //buffer[length]='\0'; return 1; } int main(){ char* buffer = new char[10]; writebuff(buffer,10); cout << "After: "<<buffer<<endl; } my question is about the terminator: should it be