Just summarizing my google search. Can malloc be used in Nesc programs?
THANKS TO TINYOS FORUM MEMBERS
Ans : Yes, program will run. But not at all recommended.
Ref: 1. http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2005-February/007712.html
2. http://www.mail-archive.com/
From Ref:1
> When i used malloc, it sometimes gives me a pointer at the > adress:0x29DB, > which is , i think, not normal because this pointer goes to the > external SRAM > (which is not present on my cricket platform). So any write at this > adresse > has no effect on further read...
The TinyOS programming methodology frowns on malloc, for several reasons: 1) No memory protection so you can smash your stack 2) Unforeseen rate mismatches can cause you to do 1 (you start receiving packets faster than you can forward them) 3) Event-driven execution models can make free()ing a hard thing to do right (hence pool allocations, etc.)
If you want dynamic allocation, look at TinyAlloc . It allows you to allocate a static chunk of RAM which you then parcel out dynamically. But using it in the presence of conflicting components is a recipe for disaster. Systems such as TinyDB
get away with it because all their parts are designed to work together.