diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-15 17:06:21 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-15 17:06:21 -0500 |
commit | 20f225bd5a557b9751439cb1857020f9ed367a6a (patch) | |
tree | eb317f370c6feabf528c43a6b9b88f0fceb95235 /lib/libtqtrla/src | |
parent | 274a42aacecfcbcbdd80e3845e3b01991b65f925 (diff) | |
download | ulab-20f225bd5a557b9751439cb1857020f9ed367a6a.tar.gz ulab-20f225bd5a557b9751439cb1857020f9ed367a6a.zip |
Fix scope and float array transfers
Diffstat (limited to 'lib/libtqtrla/src')
-rw-r--r-- | lib/libtqtrla/src/tqtrla.cpp | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/lib/libtqtrla/src/tqtrla.cpp b/lib/libtqtrla/src/tqtrla.cpp index 3fdea05..b3fc1ec 100644 --- a/lib/libtqtrla/src/tqtrla.cpp +++ b/lib/libtqtrla/src/tqtrla.cpp @@ -21,6 +21,7 @@ #include "tqtrla.h" #include <tqwidget.h> +#include <tqbuffer.h> #include <klocale.h> #include <kmessagebox.h> @@ -325,9 +326,30 @@ TQDataStream &operator<<( TQDataStream &s, const TQFloatArray &data ) { TQ_UINT32 i; TQ_UINT32 count = data.count(); s << count; - for (i=0; i<count; i++) { - s << data[i]; + + TQIODevice* dev = s.device(); + if (dev) { + // This uses the channel efficiently by writing all the data in one large block + TQBuffer ba; + ba.open(IO_ReadWrite); + TQDataStream ds(&ba); + ds.setPrintableData(s.isPrintableData()); + + for (i=0; i<count; i++) { + ds << data[i]; + } + + ba.close(); + TQByteArray buffer = ba.buffer(); + dev->writeBlock(buffer.data(), buffer.size()); + } + else { + // This uses the channel inefficiently by writing the data in byte-sized chunks + for (i=0; i<count; i++) { + s << data[i]; + } } + return s; } @@ -346,9 +368,30 @@ TQDataStream &operator<<( TQDataStream &s, const TQDoubleArray &data ) { TQ_UINT32 i; TQ_UINT32 count = data.count(); s << count; - for (i=0; i<count; i++) { - s << data[i]; + + TQIODevice* dev = s.device(); + if (dev) { + // This uses the channel efficiently by writing all the data in one large block + TQBuffer ba; + ba.open(IO_ReadWrite); + TQDataStream ds(&ba); + ds.setPrintableData(s.isPrintableData()); + + for (i=0; i<count; i++) { + ds << data[i]; + } + + ba.close(); + TQByteArray buffer = ba.buffer(); + dev->writeBlock(buffer.data(), buffer.size()); + } + else { + // This uses the channel inefficiently by writing the data in byte-sized chunks + for (i=0; i<count; i++) { + s << data[i]; + } } + return s; } |