Go Down

Topic: Pre-instances of objects in core libraries. (Read 747 times) previous topic - next topic

RoyK

Feb 26, 2010, 10:14 am Last Edit: Feb 26, 2010, 10:16 am by RoyK Reason: 1
I'd like to see some internal changes to the core libraries (hardwareserial in particular) to allow the programmer to opt out of the preinstantiation of objects.

This could be done in such a way as to not break existing code or documentation by, for example, the use of a statement like:

#define NOHARDWARESERIAL_PREINSTANCE or something like that.

In this case if the #define was present no allocation would be made for buffers and no interrupts would be enabled unless the user specifically created the object -- i.e.

hardwareserial Serial(1); // where the "1" is the Uart to use.

Without the #define things would be as they are now.

This would be especially useful when coding for the Mega which has 4 serial ports. As it is now if even one of them is used buffers are allocated for all four whether or not they are all used. I know it can be done because I've done it. Unfortunately my code has been specifically tailored to 9th bit addressing protocol so has a great deal of code that would not be of general applicability.



Go Up