Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: malloc
PostPosted: Fri Mar 23, 2012 3:37 am 
Offline

Joined: Fri Feb 24, 2012 7:36 pm
Posts: 11
I'm using a modified version of some of the example code available from Atmel for my project, but I need to use the malloc function now.

What is the best way of getting this implemented on the AT91SAM3U4?


Top
 Profile  
 
 Post subject: Re: malloc
PostPosted: Fri Mar 23, 2012 10:16 am 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
Isn't it declared in stdlib.h? Remeber to reserve memory in the heap by an appropriate entry in the scatter file.

...
ARM_LIB_HEAP 0x76FFD000 EMPTY 0x20000 {
}

ARM_LIB_STACK 0x76000000 EMPTY -0x2000 {
}
...

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: malloc
PostPosted: Sat Mar 24, 2012 6:55 am 
Offline

Joined: Fri Feb 24, 2012 7:36 pm
Posts: 11
The problem I get from compiling is that _sbrk is undefined.


Top
 Profile  
 
 Post subject: Re: malloc
PostPosted: Sat Mar 24, 2012 10:21 am 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
I haven't experienced the problem. Could you have a look at:
http://embdev.net/topic/129753
http://embdev.net/topic/152798
That the only thing I can help you

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: malloc
PostPosted: Tue Apr 24, 2012 11:28 am 
Offline

Joined: Mon Apr 23, 2012 10:32 am
Posts: 17
The _sbrk() function is a system call, which enlarges an already allocated memory block.

You should really think long and hard before pulling in these OS stuff. The whole malloc() idea (or new in C++) originates from larger systems with virtual memory and MMU. This is an environment were you assumed not to know anything of actual addresses - things which are essential in this kind of embedded systems.

Are you ready to handle out-of-memory events at runtime on your Cortex M3 application ?

If you can get away with a roll-your-own, static memory allocation, you probably spare yourself a lot of hassle.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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 post attachments in this forum

Search for:
Jump to: