         _oBuf.writeUTFBytes(value);
     }
 
+    protected function massageBuffer (buffer :ByteArray) :ByteArray
+    {
+        // we only switch buffers if we're wasting 25% and at least 64k
+        if (buffer.position < 0x10000 || 4*buffer.position < buffer.length) {
+            return buffer;
+        }
+        var newBuffer :ByteArray = new ByteArray();
+
+        buffer.readBytes(newBuffer, buffer.position);
+        return newBuffer;
+    }
+
     private var _state :int;
     private var _port :int;
 

    {
        switch(_state) {
        case ST_VIRGIN:
            return;

        case ST_CONNECTED:
            nb_read(_iBuf);

                var n :int = nb_write(_oBuf);
                _oBuf.position = pos + n;
            }

            _iBuf = massageBuffer(_iBuf);
            _oBuf = massageBuffer(_oBuf);

            break;

        case ST_WAITING:
