Log in

View Full Version : Runtime assembler generation!


Pages : 1 [2]

Bidoche
5th April 2003, 23:43
It's used by lots of other libraries and even the standard implementation of new[] returns zero on failure. new is supposed to throw std::bad_alloc on failure.... (from the C++ standard, msdn says NULL... :/ )
One can't want to check new results constantly, it has to be an exception (have to check that STLPort (the library I use) does it right)

I've also heard a lot that some people don't like exceptions. Exceptions are great and make shorter and cleaner code. Those are probablu C people who haven't even started gettting a hold why C++ is better

Maybe you can use the prepocessor to provide both versions.

Everyone is free to write a little wrapper around Assembler which throws whatever they like to throw They could always requalify the exceptions you throw

gabest
6th April 2003, 00:07
I think either caught as an exception, detected as NULL or just simply letting the program crash, there isn't much difference in the outcome when the system runs out of memory.

Bidoche
6th April 2003, 10:36
With an exception, as the stack unwinds and destroys objects, you liberate memory, and you can hope not crashing the world with you.

gabest
6th April 2003, 11:27
And then you can finally tell the user that the program must terminate itself even so because without memory it simply can't go on. If you have nothing important to save, it doesn't matter which way you choose.

Bidoche
6th April 2003, 12:29
It may help other programs to avoid crash themselves.
Besides I would always prefer a clean termination than a crash.

c0d1f1ed
6th April 2003, 13:19
Try to look at it this way: calling acquire() when no code has been generated yet isn't really an error, it just doesn't give you any result. Hence I return zero. The same applies to most other situations. I prefer to only use exceptions for truely exceptional situations.

I agree that in many situations it's easier to catch errors in only one location, instead of having to check for zero every time. But on the other hand, if you just want to know if one call succeeded, it's easier/cleaner/faster to test for zero than to write a try-catch block.

I hope you can agree a little bit with my point of view. And like I said before, you're free to change this behaviour. It's open-source! ;)

Bidoche
6th April 2003, 14:13
When subclassing I would choose private (protected ?) inheritance anyway, so there is no real point in protecting your methods anyway.

c0d1f1ed
21st April 2003, 00:42
I finally added a method to release temporary data. It's called finalize() and leaves only the generated code allocated, but still owned by the Assembler class. So it's ideal for sub-classing without worries. I'll soon create a package but now it's still in the CVS: http://sourceforge.net/cvs/?group_id=55307

I also have a demo now which clearly shows the power of soft-wiring technology: http://sourceforge.net/project/showfiles.php?group_id=55307&release_id=94233

[sh0dan: corrected the first URL]

Bidoche
2nd May 2003, 10:33
Great news, there is no reason for not subclassing now