c - When does malloc return NULL in a bare-metal environment? -


there c memory model following :

      +--------+   last address of ram       | stack  |       |   |    |       |   v    |       +--------+ ram   |        |       |        |       +--------+       |   ^    |       |   |    |       | heap   |       +--------+       |   zi   |       +--------+       |   rw   |         +========+  first address of ram 

the stack , heap space increase in opposite directions. overlapped each other in middle. questions are:

  • in bare-metal environment, when malloc return null?
  • in bare-metal environment, how prevent stack overlapping heap?

@wikiwang correct if using static, compile-time memory layout (edit although have tell malloc implementation somehow end of heap is).

if not, , assuming mean bare-metal, depends on c library implementation in board-support package. library must provide implementation of brk(2) or function having similar effect. malloc works within area of memory set brk or sbrk. example, see malloc source calling macro morecore, default sbrk. c library have use other kernel call :) .


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -