CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Dyn. memory allocation

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

Dyn. memory allocation
PostPosted: Tue Mar 15, 2011 4:51 pm     Reply with quote

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!
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 5:20 pm     Reply with quote

I got it going I think but I just reserved a lame 100Byte large area of memory fix - it's a waste but I don't get it working with dyn. memory allocation :(
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group