On Jan 29, 2008 11:36 AM, Philip Levis <[EMAIL PROTECTED]> wrote:
>
> On Jan 29, 2008, at 2:49 AM, AIGroup wrote:
>
> > I believed...
> > I'm using TinyOS 2.0.
> > I tried to compile and use these statements in my code:
> >     int *x;
> >     x=(int *)(malloc(sizeof(int)));
> >     *x=4;
> >     dbg("BlinkC", "Timer 0 fired @ %s.\nContenuto di x = %d\n",
> > sim_time_string(), *x);
> >
> > and all works well!
> > So...why using malloc() is dangerous? (as I read in some past posts)
> > Thanks for your help
>
>
> The programming manual goes into why malloc is a bad idea. Stated
> succinctly, you don't have a lot of memory and malloc couples
> component failures. If one component leaks memory, this will cause
> others to fail. It's not a PC, where mallocing too much will cause
> you to hit swap and slow down; mallocing too much will just cause you
> to crash and very possibly hang.
>
> Phil

Malloc works fine but as others have pointed out, you have to be
extremely careful. In Tenet
(http://enl.usc.edu/projects/tenet/index.html), we use malloc to
allocate various data structures, do some processing and get rid of
them.

- om_p
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to