Hello everyone,

I have a small question about NativeBoost : How does the "+" operator when
applied to a pointer translates into NativeBoost code ?

To give a bit of context, what I want to do is to reallocate some
non-contiguous bytes in memory to a buffer. Basically, I have an array of
integers in a buffer and I want to copy some chunks of it in another
buffer. The chunks are always the same size and the offset between each
chunk is always the same too.

Because a bit of actual code is easier to understand here is what I'd like
to do in Pharo :

...

int i, j;
int *data = malloc(1000*sizeof(int));
int *newData = malloc(50*sizeof(int));

// Allocate initial data
for (i = 0 ; i < 1000, i++) {
  data[i] = i;
}

//Copy desired chunks into new buffer
for (i = 0; i < 5; i++ ) {
  memcpy( newData + j*10, data + 200 + j*30, 10*sizeof(int));
  j++;
}

free(data);

...

Here basically I'll get in my buffer chunks of 10 integers starting at 200
with an offset of 30 between chunks, and this 5 times. (200 201 202 ... 208
209 230 231 ... 238 239 260 ... 328 329).

I am okay with the malloc, memcpy and free but I don't know how to handle
the "+" operator in my memcpy function.

Thank you,

Matthieu

Reply via email to