I observed that size of long is always equal to the WORD size of any given CPU architecture. Is it true for all architectures? I am looking for a portable way to represent a WORD sized variable in C.
...
I'm writing a memory allocator, and I need a way to store an integer inside of a chunk of memory. This integer will represent the size of the block so I can navigate to the end given the pointer to the beginning.
Here's my test example:
// EDIT: Declared space for testInt
int* testInt = new int;
head_ptr = (char*) malloc(4*1024*1...
Hi,
I am working in mixed mode (managed C++ and C++ in one assembly). I am in a situation something like this.
ManagedStructure ^ managedStructure = gcnew ManagedStructure();
//here i set different properties of managedStructure
then I call "Method" given below and pass it "& managedStructure"
Method(void *ptrToStruct)
{
Manag...
I'm working on implementing a log based file system for a file as a class project. I have a good amount of it working on my 64 bit OS X laptop, but when I try to run the code on the CS department's 32 bit linux machines, I get a seg fault.
The API we're given allows writing DISK_SECTOR_SIZE (512) bytes at a time. Our log record consists...
Hi,
I want to copy an int array to another int array. They use the same define for length so they'll always be of the same length.
What are the pros/cons of the following two alternatives of the size parameter to memcpy()?
memcpy(dst, src, ARRAY_LENGTH*sizeof(int));
or
memcpy(dst, src, sizeof(dst));
Will the second option always ...
according to http://www.cplusplus.com/reference/clibrary/cstring/memcpy/ c++'s memcpy takes three parameters: destination, source and size/bytes. it also returns a pointer. why is that so? aren't the parameters enough to input and copy data.
or am i misunderstanding something? the examples don't use the return value
...
After learning that both strncmp is not what it seems to be and strlcpy not being available on my operating system (Linux), I figured I could try and write it myself.
I found a quote from Ulrich Drepper, the libc maintainer, who posted an alternative to strlcpy using mempcpy. I don't have mempcpy either, but it's behaviour was easy to r...
I've been learning how to NOP functions in C++ or even C but there are very few tutorials online about it. I've been googling for the past few hours now and I'm just stuck. Here is my code.
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;
//#define NOP 0x90
byte NOP[] = {0x90};
void enableDebugPrivil...
When using memset or memcpy within an Obj-C program, will the compiler optimise the setting (memset) or copying (memcpy) of data into 32-bit writes or will it do it byte by byte?
...
What is the difference between memcpy() and strcpy()? I tried to find it with the help of a program but both are giving the same output.
int main()
{
char s[5]={'s','a','\0','c','h'};
char p[5];
char t[5];
strcpy(p,s);
memcpy(t,s,5);
printf("sachin p is [%s], t is [%s]",p,t);
return 0;
}
Output
sachin p i...
Is is possible to memcpy from a double array to a float array safely?
...
I have a function that is doing memcpy, but it's taking up an enormous amount of cycles. Is there a faster alternative/approach than using memcpy to move a piece of memory?
...
Hey all :)
I have a problem my src pointer of memcpy is pointing wrong.
unsigned char* lpBuffer is a buffer that contains my bytes, i checked with olly.
The code:
IMAGE_DOS_HEADER iDOSh;
memcpy(&iDOSh,lpBuffer,sizeof(iDOSh));
The problem is that lpBuffer points wrong, output from debugger is
dest = 002859E8 RIGHT
src = 000001D8 ...
Hello,
I have a LPBYTE array (taken from file) and I need to copy it into LPTSRT (actually into the clipboard). The trouble is copying work but unstable, sometime an exception was thrown (not always) and I don't understand why. The code is:
FILE *fConnect = _wfopen(connectFilePath, _T("rb"));
if (!fConnect)
return;
fseek(fCo...
When I define an array on the device (that is initialized with a "Hello" string in this example) and try to copy this to the host, I get the error code cudaErrorInvalidValue. However, from inside a kernel, the d_helloStr[] can be accessed. Referring to the CUDA programming guide chapter B.2.1, such a variable should also be accessible th...
Hi,
Basically in the code below, my final array does not seem to have the contents from function1(). Any ideas on why I can't get this to work ? Thanks.
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
unsigned char *function1()
{
unsigned char array2[] = { 0x4a,0xb2 };
return (array2 );
}
main()
...
In C, what will happen if I supply a signed integer especifically a negative integer as the 3rd argument to the memcpy function?
Example:
memcpy(destBuf, source, -100*sizeof(source))
Will the result of -100*sizeof(source) be interpreted by memcpy as unsigned?
Thanks!
...
I have a structure that has a dynamic array in it. I have defined two of these structures.
I fill the array in the first structure, then use a line like
memcpy(R->v, A->v, A->n*sizeof(double)
where v is the array that has been dynamically allocated, and n is the number of entries.
R and A are the same type if that matters.
The probl...
Hello all,
I encounter problem with memcpy in C. Here is the code :
typedef struct {
CPY_IM009_DEF
}message;
message msg;
with CPY_IM009_DEF is a struct in other files. Then I try this
char wx_msg_buf[8192];
memset(wx_msg_buf, 32, sizeof (wx_msg_buf));
memcpy(wx_msg_buf, &msg, sizeof (msg));
when I check the size :
sizeof (msg)...
On occasion, the following code works, which probably means good concept, but poor execution. Since this crashes depending on where the bits fell, this means I am butchering a step along the way. I am interested in finding an elegant way to fill bufferdata with <=4096 bytes from buffer, but admittedly, this is not it.
EDIT: the error ...