cnaldaba / java-simple-serial-connector

Automatically exported from code.google.com/p/java-simple-serial-connector
0 stars 0 forks source link

"Garbage-less" read method that takes a byte array instead of allocating a new one every-time... #41

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
While a Java programmer should refrain from thinking too much about
optimizing object/array allocation, in practice the garbage collection pauses
can become a problem which becomes critical in near-real-time applications.
I am building control software for state-of-the art microscopes and try to 
minimize
object allocation, especially when it's nit really necessary.
Java can behave very well for this sort of applications -- reducing object 
allocation is 
an essential trick to achieve that. 
(Imagine an intense serial traffic with thousands of messages per seconds which 
would swamp the GC and make it spend a lot of time cleaning up the mess...)

It would be nice to have the possibility to have a method like this one:

    public byte[] readBytes(byte[] bytes) throws SerialPortException {
        checkPortOpened("readBytes()");
        return serialInterface.readBytes(portHandle, bytes);
    }

which would use an existing array (which implicitly defines a read length)
instead on internally allocating a new array for every read.

Actually I was trying to see if I could make the change myself, and send it to 
you,
but i don't see any makefile for the native code, how do you compile?

Original issue reported on code.google.com by royerloi...@gmail.com on 10 Jun 2013 at 9:47