With the code:
int nsize;
int * buffer;
char TargetBuffer[4096];
const SIZE_T buffersize = (320*240) * sizeof(int);
buffer = (int *) malloc(bufferSize);
// fill buffer with data
nsize = 0;
while(nsize < buffersize)
{
// HERE after some loops i get Access Violation
memcpy(TargetBuffer, buffer + nsize, 4096);
// do stuff with TargetBuffer
nsize += 4096;
}
Why am I get the Access Violation? What should I change?
When you add
buffer + nsizeyou have to realize that you are actually addingbuffer + (nsize * (sizeof(int))since it’s aint *when you are doing pointer arithmetic.So it probably has something to do with it. Try incrementing nsize by
nsize += 4096/sizeof(int)or something more clever.