memcpy

Create a copy class method for a Python object containing a Swig object

喜欢而已 提交于 2021-02-08 09:18:30
问题 I have created a Python class with an attribute that is a Swig object (which happens to be a wrapper of a C structure). I want to be able to create copies of that class, e.g., by defining a __copy__ method, that contain independent copies of the Swig object (using the copy modules' copy class just creates a pointer to the original object, and deepcopy fails). Does anyone know if you can just copy chunks of memory in Python, and use this to copy the attribute containing the Swig object? Or,

Create a copy class method for a Python object containing a Swig object

霸气de小男生 提交于 2021-02-08 09:18:12
问题 I have created a Python class with an attribute that is a Swig object (which happens to be a wrapper of a C structure). I want to be able to create copies of that class, e.g., by defining a __copy__ method, that contain independent copies of the Swig object (using the copy modules' copy class just creates a pointer to the original object, and deepcopy fails). Does anyone know if you can just copy chunks of memory in Python, and use this to copy the attribute containing the Swig object? Or,

Is it technically impossible to implement memcpy from scratch in Standard C?

一世执手 提交于 2021-02-07 05:11:59
问题 Howard Chu writes: In the latest C spec it is impossible to write a "legal" implementation of malloc or memcpy. Is this right? My impression is that in the past, the intent (at least) of the standard was that something like this would work: void * memcpy(void * restrict destination, const void * restrict source, size_t nbytes) { size_t i; unsigned char *dst = (unsigned char *) destination; const unsigned char *src = (const unsigned char *) source; for (i = 0; i < nbytes; i++) dst[i] = src[i];

Is it technically impossible to implement memcpy from scratch in Standard C?

霸气de小男生 提交于 2021-02-07 05:11:26
问题 Howard Chu writes: In the latest C spec it is impossible to write a "legal" implementation of malloc or memcpy. Is this right? My impression is that in the past, the intent (at least) of the standard was that something like this would work: void * memcpy(void * restrict destination, const void * restrict source, size_t nbytes) { size_t i; unsigned char *dst = (unsigned char *) destination; const unsigned char *src = (const unsigned char *) source; for (i = 0; i < nbytes; i++) dst[i] = src[i];

Swift memcpy doesn't have any effect when used with ZMQ zmq_msg_data

╄→尐↘猪︶ㄣ 提交于 2021-01-29 20:31:11
问题 I've been trying to write a libzmq wrapper for Swift by building off of an existing wrapper called SwiftyZeroMQ. However, for our purposes, we require the usage of raw UDP which means we need to use ZeroMQ's Radio/Dish draft method. I've been able to successfully write a wrapper for receiving data via the Dish socket but I'm now trying to write a wrapper for sending data via the Radio socket. There doesn't seem to be any stuff online regarding how to write a function to send data via the

Convert safely between uint8_t[8] & uint64_t via cast?

放肆的年华 提交于 2021-01-27 17:00:48
问题 The way I'm currently doing it (I'd prefer to get rid of the memcpy call): uint64_t integer; uint8_t string[8]; ... memcpy(&integer, &string, 8); //or swap the parameters Assuming integer array length to always be a multiple of 8 (64 bits total allocation) is a straight cast possible given compiler padding / alignment concerns? 回答1: There is absolutely no need to avoid or replace a memcpy() call if you're striving for optimization. Every modern optimizing compiler won't emit a call and

memset和memcpy使用教训

限于喜欢 提交于 2020-11-14 11:59:00
前两天在调试代码时,发现了一个比较低级的错误:对于memset和memcpy接口的参数错误使用。在这里总结一下,避免以后再犯。 先说一下我的错误教训。 memset的使用,代码如下 ? 1 2 3 4 5 INT16 i16ADBuf[4096]; ... memset (i16ADBuf, 6, sizeof (i16ADBuf)); ... 原意是想把数组的每个元素初始化成6,结果调试给出的元素值为1542,让我莫名奇妙,怎么都想不通,后来才发现自己的错误,你发现了吗? memcpy的使用,代码如下 ? 1 2 3 4 5 6 7 INT16 i16ADBuf[4096]; INT16 g_i16ADBuf[4096]; int pointNum = 205; ... memcpy (g_i16ADBuf,i16ADBuf, pointNum); ... 目的是想拷贝已有的pointNum个元素到全局数组中去,结果却只拷贝了一半的元素到目的数组中,在整个应用中我有多处都犯了这个错误。 教训总结: C标准库中头文件中memset和memcpy的接口为: ? 1 2 3 4 5 6 7 #include <string.h> //把buf中的前count个字符替换为ch,并返回buf。 void * memset ( void *buf, int ch, size_t count)

ARM/neon memcpy optimized for *uncached* memory?

ⅰ亾dé卋堺 提交于 2020-05-25 05:29:09
问题 I'm using a Xilinx Zynq 7000 ARM-based SoC. I'm struggling with DMA buffers (Need help mapping pre-reserved **cacheable** DMA buffer on Xilinx/ARM SoC (Zynq 7000)), so one thing I pursued was faster memcpy. I've been looking at writing a faster memcpy for ARM using Neon instructions and inline asm. Whatever glibc has, it's terrible, especially if we're copying from an ucached DMA buffer. I've put together my own copy function from various sources, including: Fast ARM NEON memcpy arm Inline