::new causes turn-off if out of memory
::new causes turn-off if out of memory
If you allocate memory using standard C++ operator ::new, but don't have enough, the DS just turns off. I think this was introduced in a recent libnds update. Does anyone know how to override this behavior?
Re: ::new causes turn-off if out of memory
libnds allows for the following function to be created. It is called when the program exits with a non zero value. it needs to be defined as C code to link properly.
Code: Select all
void systemErrorExit(int rc) {
}
-
- Site Admin
- Posts: 2003
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: ::new causes turn-off if out of memory
Or alternatively you can override the new & delete operators so they return NULL instead of throwing an exception.
And of course you can tell new not to throw the exception.
Another option is to catch the exception but, as for systemErrorExit, you won't have the opportunity to deal with the error at the point of failure.
Code: Select all
#include <cstdlib>
void* operator new (size_t size) {
return malloc(size);
}
void operator delete (void *p) {
free(p);
}
Code: Select all
#include <new>
char *array = new(std::nothrow) char[4096*1024];
Re: ::new causes turn-off if out of memory
If you are using other C++ features like the standard library you might want to read this:
http://www.coranac.com/2009/02/some-int ... code-size/
http://www.coranac.com/2009/11/sizeof-new/
http://www.coranac.com/2009/02/some-int ... code-size/
http://www.coranac.com/2009/11/sizeof-new/
Donate to devkitPro - help us stay alive!
Re: ::new causes turn-off if out of memory
Holy smokes, that was some good info. I saved 282'624 bytes by uncommenting a define in my TinyXML header that switched the use of iostream to it's own stream and string handler. I would have worked for forever to get that kind of save, so I owe you one!
I tried the systemErrorExit, but couldn't get it to work. I used extern "C" for it's declaration in my .cpp file, but I probably did something wrong and will try it again later.
I might consider overriding new and delete as suggested as that also seem to be a way to save some code-size, but it sounds a bit messy.
I tried the systemErrorExit, but couldn't get it to work. I used extern "C" for it's declaration in my .cpp file, but I probably did something wrong and will try it again later.
I might consider overriding new and delete as suggested as that also seem to be a way to save some code-size, but it sounds a bit messy.
Re: ::new causes turn-off if out of memory
I'm so glad I check up on these kind of threads. Lot of memory to be saved by following those guidelines.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests