Hi Everyone,
I finally seem to have located the orign of a bug i was experiencing.
I think realloc works a kind of funky. The situation is as follows:
- i allocate a buffer of 2 bytes size (malloc)
- i reallocate (realloc) the same buffer and ask it to expand to a size of 4 bytes
- the realloc method returns NULL
This is the culprit:
pulsebuffer = (unsigned int *)realloc(pulsebuffer , newsize );
but when i code it as follows, the memory allocation works ok:
unsigned int * prevpulsebuffer = pulsebuffer;
pulsebuffer = (unsigned int *) malloc(newsize);
for (int idx=0;idx<pulsebufferlength;idx++) pulsebuffer[idx] = prevpulsebuffer[idx];
free(prevpulsebuffer);
What am i missing?
thanks, Sander