memcpy vs assignment in C
Under what circumstances should I expect memcpys to outperform assignments on modern INTEL/AMD hardware? I am using GCC 4.2.x on a 32 bit Intel platform (but am interested in 64 bit as well). ...
Under what circumstances should I expect memcpys to outperform assignments on modern INTEL/AMD hardware? I am using GCC 4.2.x on a 32 bit Intel platform (but am interested in 64 bit as well). ...
Let's say I have some pointers called: char * pChar; int * pInt; I know they both simply hold memory addresses that point to some other location, and that the types declare how big the memory location is pointed to by the particular pointer. So for example, a char might be the size of a byte on a system, while an int may be 4 bytes.. ...
Hi, I am attempting to copy the members of a struct containing a mixture of ints, char's and arrays of chars into a byte array to send to a serial line. So far I have // struct msg_on_send // { // char descriptor_msg[5]; // int address; // char space; // char cmdmsg[5]; // char CR; // char LF; // }; /...
Some people seem to think that C's strcpy() function is bad or evil. While I admit that it's usually better to use strncpy() in order to avoid buffer overflows, the following (an implementation of the strdup() function for those not lucky enough to have it) safely uses strcpy() and should never overflow: char *strdup(const char *s1) { ...
The theoretical maximum of memory bandwidth for a Core 2 processor with DDR3 dual channel memory is impressive: According to the Wikipedia article on the architecture, 10+ or 20+ gigabytes per second. However, stock memcpy() calls do not attain this. (3 GB/s is the highest I've seen on such systems.) Likely, this is due to the OS vend...
I have this bit of code that is outputting the wrong results. #include <stdio.h> #include <string.h> int main() { unsigned char bytes[4]; float flt=0; bytes[0]=0xde; bytes[1]=0xad; bytes[2]=0xbe; bytes[3]=0xef; memcpy( &flt, bytes, 4); printf("bytes 0x%x float %e\n", flt, flt); return 0; } the output that I get ...
i am trying to write a memcpy function that does not load the source memory to the cpu cache. The purpose is to avoid cache pollution. The memcpy function below works, but pollutes the cache like the standard memcpy does. i am using P8700 proccesoor with visual C++ 2008 express. i see the cpu cache usage with intel vtune. void memcpy(c...
I recently stumbled across an article that claims Microsoft is banning the memcpy() function in its secure programming shops. I understand the vulnerabilities inherent in the function, but is it necessary to ban its use entirely? Should programs I write be avoiding memcpy() entirely, or just ensuring that it's used safely? What alternat...
Duplicate: Memcpy() in secure programming? According to "Please Join me in welcoming memcpy() to the SDL Rogues Gallery" memcpy is being banned as unsafe. It makes sense that gets(), strcpy and similar apis where the destination size is unclear. Is memmove() next? ...
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) { /*...
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[...
I would like to copy a relatively short sequence of memory (less than 1 KB, typically 2-200 bytes) in a time critical function. The best code for this on CPU side seems to be rep movsd. However I somehow cannot make my compiler to generate this code. I hoped (and I vaguely remember seeing so) using memcpy would do this using compiler bui...
I wish to copy content of specific length from one buffer to another from a specific starting point. I checked memcpy() but it takes only the length of content to be copied while I want to specify the starting index too. Is there any function which can do this? Or is there any good approach to do it with existing memcpy function. ...
Hi Everyone, For a networked application, the way we have been transmitting dynamic data is through memcpying a struct into a (void*). This poses some problems, like when this is done to an std::string. Strings can be dynamic length, so how will the other side know when the string ends? An idea I had was to use something similiar to Java...
I'm looking through some code for learning purposes. I'm working through this portion of code. // e.g. const unsigned char data={0x1,0x7C ... } unsigned char buf[40]; memset(buf,0,40); buf[0] = 0x52; memcpy(buf+1, data, length); // What does buf+1 do in this situation? On the last line where memcpy is called what does buf+1 do? buf is...
I have the following two structs where "child struct" has a "rusage struct" as an element. Then I create two structs of type "child" let's call them childA and childB How do I copy just the rusage struct from childA to childB? typedef struct{ int numb; char *name; pid_t pid; long userT; ...
I've read the function headers, but I'm still not sure what exactly the difference is in terms of use cases. Thanks! ...
Classic memcpy gotcha with C arrays as function arguments. As pointed out below, I have an error in my code but the erroneous code worked in a local context! I just encountered this weird behaviour in a porting job, where I'm emulating the Macintosh Picture opcode playback using objects. My DrawString object was drawing garbage on playb...
I am using memcpy in my application. memcpy crashes randomely and below is the logs i got in Dr.Watson files. 100181b5 8bd1 mov edx,ecx 100181b7 c1e902 shr ecx,0x2 100181ba 8d7c030c lea edi,[ebx+eax+0xc] 100181be f3a5 rep movsd 100181c0 8bc...
I have posted my problem in the CUDA forums, but not sure if it's appropriate to post a link here for more ideas in case there are significant number of different audiences between the two forums. The link is here. I apologize for any inconvenience and appreciate any comments on this question, as I haven't heard back yet on some specific...