cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
Dyn. memory allocation |
Posted: Tue Mar 15, 2011 4:51 pm |
|
|
Hi There,
I am writing an application where I want to receive data over rs232 from UART1 and forward them to UART2 - assuming the same baudrate. Now I am only on the receiving part. I wrote an isr that kicks in once the byte is ready to be received. Then i check certain things and I want to store it in an array from where it can be read out again and forwarded to UART2.
I have this code:
Code: |
int8 *buffer1 = calloc(1,1);
buffer1 = realloc(buffer,++buffersz);
if (!buffer1 && buffersz) {
fprintf(DEBUG,"ERROR: Couldn't allocate memory at 0x%x",buffer1);
}
buffer = buffer1;
buffer[buffersz-1]=ch; |
Which doesn't seem to work properly and i'm not sure why, assume ch is the incoming character. I want to allocate some space with realloc() to store the newly received byte but it doesn't go anywhere, i'm confused...
Thanks for a little help here! |
|