0 Members and 1 Guest are viewing this topic.
So I recently got into TI-Nspire CX programming, and I've had this looming worry... Does the OS deal with cleanup after program exit? i.e. say I malloc some memory and exit without freeing it. Does the OS recognize that it should be freed?
Furthermore, say I open a file and then shut down the program without closing it. Would there be any problems stemming from that?
void main(int argc, char **argv) { fopen(argv[0], "rb"); }
It's gonna feel weird having to take actual measures to get out of a crash.
1- Is there any risk stemming from pointer shenanigans? Like, say I forget to assign a pointer and write to it. Is there any chance of me permanently messing up my calculator?
2- This one should be more evident but I trust that malloc'd memory is freed upon calculator reset?
EDIT: Bonus third (sorry for so many!), is there any way to track allocated memory so that I may be able to find out if my program has a memory leak?
QuoteIt's gonna feel weird having to take actual measures to get out of a crash.Well, if your program crashes, it's not possible to recover and the calc resets.abort and std::terminate (C++) are caught and it tries to recover from it, but that's not possible sometimes.
QuoteEDIT: Bonus third (sorry for so many!), is there any way to track allocated memory so that I may be able to find out if my program has a memory leak?There is no valgrind for ndless, but you can try to modify libsyscalls in the Ndless-SDK a bit to print something on each malloc and free and track it manually over the serial port or have an internal counter: https://github.com/ndless-nspire/Ndless/blob/master/ndless-sdk/libsyscalls/stdlib.cpp#L104
Thank you so so so much for your help!Quote from: Vogtinator on September 09, 2015, 03:19:56 pmQuoteIt's gonna feel weird having to take actual measures to get out of a crash.Well, if your program crashes, it's not possible to recover and the calc resets.abort and std::terminate (C++) are caught and it tries to recover from it, but that's not possible sometimes.Maybe crash isn't the proper word.. I meant as in, failure to read a file and I end up aborting for example. On the computer all I have to do is have the program quit, but here I see myself implementing some ad-hoc version of exceptions using gotos.
Quote from: Vogtinator on September 09, 2015, 03:19:56 pmQuoteEDIT: Bonus third (sorry for so many!), is there any way to track allocated memory so that I may be able to find out if my program has a memory leak?There is no valgrind for ndless, but you can try to modify libsyscalls in the Ndless-SDK a bit to print something on each malloc and free and track it manually over the serial port or have an internal counter: https://github.com/ndless-nspire/Ndless/blob/master/ndless-sdk/libsyscalls/stdlib.cpp#L104How would I go about, say, logging things to a file perhaps? I've tried using the C IO functions, but I found myself unable to write things? It created the file and everything, but failed when I tried to write to it.