FAQ Database Discussion Community


memcpy and memset function to java

java,c,memcpy
I am currently adapting a DLL written in C to Java and I am having problems with the memcpy and memset C functions. Here is what I want to convert (it's not the whole code) : int res = 0; int bytes_written = 0; int totalsize; int reportid; hid_device *handle;...

Python interpretation of bytes. (C memcpy)

c,python-3.x,memcpy
i am new in python. I try to rewrite some c++ code in python, i get data from serial port (we used our own protocol) and need to convert bytes to value in C++ i use something like this (bytes in little endian but we can get custom start bits...

How to copy memory starting at address finer than the addressable granularity of your system?

c,memcpy
I'm thinking about memcpy, where the src pointer that is passed might be an odd memory address. Is this possible? And, if so, can it be implemented? If for my system, memory is addressable in 32bit (4Byte) blocks: 0x00001000 0x00001020 0x00001040 0x00001060 How can I copy five bytes from midway...

remove characters from string in c

c,string,memcpy
I'm having an issue removing characters from a string. I have been able to identify the characters to remove and store them as a new string but I would like a code that enables me to remove the new string's characters from the original string (where I've labelled as xxxxxxxx)....

fastest way to blit image buffer into an xy offset of another buffer in C++ on amd64 architecture

c++,x86-64,memcpy,blit,libdispatch
I have image buffers of an arbitrary size that I copy into equal-sized or larger buffers at an x,y offset. The colorspace is BGRA. My current copy method is: void render(guint8* src, guint8* dest, uint src_width, uint src_height, uint dest_x, uint dest_y, uint dest_buffer_width) { bool use_single_memcpy = (dest_x ==...

Understanding CUDA profiler output (nvprof)

cuda,memcpy,nvprof
I'm just looking at the following output and trying to wrap my mind around the numbers: ==2906== Profiling result: Time(%) Time Calls Avg Min Max Name 23.04% 10.9573s 16436 666.67us 64.996us 1.5927ms sgemm_sm35_ldg_tn_32x16x64x8x16 22.28% 10.5968s 14088 752.18us 612.13us 1.6235ms sgemm_sm_heavy_nt_ldg 18.09% 8.60573s 14088 610.86us 513.05us 1.2504ms sgemm_sm35_ldg_nn_128x8x128x16x16 16.48% 7.84050s 68092...

Initializing, constructing and converting struct to byte array causes misalignment

c,arrays,pointers,struct,memcpy
I am trying to design a data structure (I have made it much shorter to save space here but I think you get the idea) to be used for byte level communication: /* PACKET.H */ #define CM_HEADER_SIZE 3 #define CM_DATA_SIZE 16 #define CM_FOOTER_SIZE 3 #define CM_PACKET_SIZE (CM_HEADER_SIZE + CM_DATA_SIZE +...

double free or corruption error on free

c,malloc,free,memcpy
this is the piece of code i use to create my char array on heap int currentArraySize = 10; char **finalArray = malloc(sizeof(char*)*currentArraySize); char buf[6] = "hello"; for(int b=0; b<currentArraySize; b++ ) { char * tmpString = (char*)malloc(sizeof(char)*6); //copy the contents of buf to newly allocated space tmpString strncpy(tmpString,buf,6); finalArray[b]...

memcpy: starting address index of sun_path of unix socket

c,sockets,memcpy
So I have code as below for unix socket initialization #define IETADM_NAMESPACE "IET_ABSTRACT_NAMESPACE" struct sockaddr_un addr; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; memcpy((char *) &addr.sun_path + 1, IETADM_NAMESPACE, strlen(IETADM_NAMESPACE)); I got that memcpy copies IETADM_NAMESPACE starting at index address i.e. &addr.sun_path + 1. My question is about the + 1...

Using memcpy to copy an array of objects

c++,arrays,object,memcpy
Recently I have encountered the error double free or corruption error in my project. After some test runs , the problem is pinned down to the copy function which uses memcpy. class Pen { string make; string model; string color; public: Pen(); } class A { private: Pen* array; //an...

can memcpy for std::aligned_storage?

c++,c++14,memcpy,object-lifetime
std::aligned_storage::type is POD type. POD type can memcpy. However, What happens if placement new non-trivially-copyable type to std::aligned_storage? Can it memcpy that std::aligned_storage? non-trivially-copyable type(non-POD type) can NOT memcpy, Behavior is undefined. If std::aligned_storage memcpy non-trivially-copyable type, is it also undefined behavior? #include <new> #include <type_traits> #include <cstring> #include <iostream>...

using memcpy to copy arrays passed as parameters

c,arrays,pointers,memcpy
I want to copy the content of some char-arrays passed as parameters in a function to another char-arrays. So I passed these arrays as pointers (passing by reference). Then I used memcpy to copy the content of these arrays to some other arrays. But the copying-process was not too exact,...

Why does the console cout some wrong letters after memcpy of a char*

c++,buffer,memcpy
I copy a char* to a char* and get it back and coutit. char buffer[100] = { 0 }; char* name = "foo"; int bar = 12345; memcpy(buffer, &(bar), 4); memcpy(buffer + 4, name, 3); int result = 0; memcpy(&result, buffer, 4); char backname[3]; memcpy(backname, buffer + 4, 3); std::cout...

function address cast to char array

c,function,casting,memcpy
For my educational purposes I was wondering if there is an alternative way with memcpy() to the following code for the function address casting to an array of chars? #include <stdio.h> #include <string.h> typedef void (*_vfp)(void); #define FPSZ sizeof(_vfp) union rcast { _vfp fp; char fp_c[FPSZ]; } rc; void a(void){...

Memcpy leading to block freed twice error

c++11,stl,memcpy,stlmap
I have a map which I am filling as needed. To get the contents of the map out into another variable I am using memcpy. If the memcpy line is commented, I see the output print correctly displayed. 100 => 1234 Fruits If I uncomment the memcpy, I see the...

copying the content of an dynamic array of structs into another dynamic array using memcpy

c,struct,malloc,memcpy
I want to copy the content of a dynamic array containing 2 structs to another dynamic array of the same size. I need an exact copy. When I compile, I get these 2 errors at the last line: invalid use of undefined type ‘struct student’ & dereferencing pointer to incomplete...

memcpy or std::copy for my particular application

c++,algorithm,memcpy
I'm attempting to author a C++ wrapper to some legacy C code to increase it's type safety and make it less of a PITA to use. The legacy code interacts with pointers in shared memory. POD structures are cast from these pointers. Since it's shared memory, these structures are guaranteed...

segmentation fault after memcpy and free

c,segmentation-fault,free,memcpy
I a new C programmer. I try to remove one element from a static array and copy the rest on a dynamic array. The program worked fine but after free() I get a segmentation fault. I think that the pointer temp is pointing to some memory on stack that's why...

memcpy issue -> trying to copy an array of struct

c++,arrays,struct,memcpy,memmove
I am completely lost on why memcpy or memmove is not working for me. I am trying to copy a array of struct (joblist) to another array of same struct (Q) to use for data manipulation, while keeping my original array intact. I have spent a lot of time on...

Audio Queue Buffer Empty Error

ios,objective-c,buffer,memcpy,audioqueue
I allocate buffers and start audio queue like // allocate the buffers and prime the queue with some data before starting AudioQueueBufferRef buffers[kNumberPlaybackBuffers]; isDone = false; packetPosition = 0; int i; for (i = 0; i < kNumberPlaybackBuffers; ++i) { CheckError(AudioQueueAllocateBuffer(queue, packetBufferSize, &buffers[i]), "AudioQueueAllocateBuffer failed"); // manually invoke callback to...