----- Ursprüngliche Nachricht ----- Von: Sergio Campamá Gesendet am: 19 Aug 2011 14:39:52
> I am currently building a somewhat complex application for the MSP430, and > it randomly crashes and I don't seem to know why. I have a suspicion that > it's RAM related, because I call many mallocs (I have checked that I free > the memory after it's no longer needed), but maybe I am filling up the RAM > and when it does, it crashes... How can I check at runtime the amount of > memory free in RAM? Is there any function that will tell me this? the problem with malloc is that it can easily cause heap congestion. If you always malloc and free the same size, it isn't a problem. But when you have different zizes and do not free them in reverse order, you might end up with one used byte here, one used byte there and in between not enough space for the next malloc. It's always a good thing to bail out if malloc returns null. I use malloc too, but only for dynamically reserving data space that is never freed again (but not known at compile-time). (well, that's not entirely true, my multithreader reserves stack space for new threads dynamically, and threads may end, freeing this space again. But in my projects no thread ever ends) Also, malloc needs some bytes additional ram for organization. I don't know the MSP implementation, but unde rDOS, it was using space immediately before the allocated ram, so a free can check whether you're freeing a malloced object, and may also join freed areas. All used and free areas form a chain, connecteed by this data. And even if the MSP implementation does not use full 16 bytes for each data block (as DOS did), it is still wasted ram (and you have to store the pointer to it in a variable too, so more space needed). You should consider other types of dynamic data storage. Or a static storage mechanism. JMGross ------------------------------------------------------------------------------ Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 _______________________________________________ Mspgcc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mspgcc-users
