首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >优化ByteArray拷贝

优化ByteArray拷贝
EN

Stack Overflow用户
提问于 2011-11-14 14:17:55
回答 1查看 1K关注 0票数 0

下面是flashlight-VNC库中的代码片段,它(使用ByteArray.inflate)解压缩传入的字节流。

代码语言:javascript
运行
复制
package com.flashlight.zlib
{

    import com.flashlight.utils.TimeTracker;

    import flash.utils.ByteArray;

    import mx.logging.ILogger;
    import mx.logging.Log;

    public class Inflater {
        private var lastDeflate:ByteArray;

        public function uncompress(compressedData:ByteArray):ByteArray {
            var uncompressedData:ByteArray = new ByteArray();
            var dataOffset:int = lastDeflate ? 0 : 2;

            TimeTracker.startTimer("TightEncoding[CopyCompresion]");
            if (lastDeflate) {
                var dictionarySize:int = lastDeflate.length > 32768 ? 32768 : lastDeflate.length;
                uncompressedData.writeByte(0x00);
                uncompressedData.writeByte(dictionarySize );
                uncompressedData.writeByte(dictionarySize >> 8);
                uncompressedData.writeByte(~dictionarySize);
                uncompressedData.writeByte((~dictionarySize) >> 8 );
                uncompressedData.writeBytes(lastDeflate,lastDeflate.length - dictionarySize, dictionarySize);
            }
            uncompressedData.writeBytes(compressedData,dataOffset,compressedData.length-dataOffset);
            TimeTracker.stopTimer("TightEncoding[CopyCompresion]");
            uncompressedData.writeByte(0x01);
            uncompressedData.writeUnsignedInt(0x0000FFFF);

            TimeTracker.startTimer("TightEncoding[Realdecompress]");
            uncompressedData.inflate(); 
            TimeTracker.stopTimer("TightEncoding[Realdecompress]");

            lastDeflate = uncompressedData;
            uncompressedData.position = dictionarySize;

            return uncompressedData;
        }

    }
}

有一个来自服务器的持续不断的压缩数据流,该数据流被Inflater类逐个块地膨胀。在这个类中,inflate()和writeBytes()方法总共占用了99%的时间。inflate()已经是本机调用。

如何优化writeBytes调用?我们可以跳过它,以其他方式重写代码,或者有更好的优化方法来做ByteArray复制的事情吗?

EN

回答 1

Stack Overflow用户

发布于 2011-11-15 16:49:33

不确定ByteArray是否可以优化,只要它是一个原生闪存类。我猜你可以尝试一些第三方库/框架,比如Fluorine或Alchemy来调用可能更快的C++算法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8117989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档