FileReference.save()复制的ByteArray [英] FileReference.save() duplicates ByteArray

查看:197
本文介绍了FileReference.save()复制的ByteArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到使用FileReference.save内存问题()。我的Flash应用大量实时数据的产生,需要此数据保存到本地文件。据我了解,闪存10(而不是AIR)不支持流到一个文件中。但是,什么是更糟糕的是,FileReference.save()复制所有数据保存前。我一直在寻找的解决方法,这增加了一倍的内存使用情况,并考虑以下方法:

I've encountered a memory problem using FileReference.save(). My Flash application generates of a lot of data in real-time and needs to save this data to a local file. As I understand, Flash 10 (as opposed to AIR) does not support streaming to a file. But, what's even worse is that FileReference.save() duplicates all the data before saving it. I was looking for a workaround to this doubled memory usage and thought about the following approach:

如果我传递的ByteArray的自定义子类作为参数传递给FileReference.save(),在此ByteArray子类将覆盖所有读取*()方法。被覆盖的读取*()方法将等待一件件地被我的应用程序生成的数据,返回这片数据,并立即从内存中删除。我知道有多少数据将被生成的,所以我也可以覆盖长/方bytesAvailable方法。

What if I pass a custom subclass of ByteArray as an argument to FileReference.save(), where this ByteArray subclass would override all read*() methods. The overridden read*() methods would wait for a piece of data to be generated by my application, return this piece of data and immediately remove it from the memory. I know how much data will be generated, so I could also override length/bytesAvailable methods.

将有可能?你能给我一些提示怎么办呢?我创建的ByteArray的一个子类,注册一个别名,通过该子类的实例FileReference.save(),但不知何故FileReference.save()似乎把它只是因为它是一个ByteArray实例,并且不调用任何我重写的方法...

Would it be possible? Could you give me some hint how to do it? I've created a subclass of ByteArray, registered an alias for it, passed an instance of this subclass to FileReference.save(), but somehow FileReference.save() seems to treat it just as it was a ByteArray instance and doesn't call any of my overridden methods...

非常感谢您的帮助!

推荐答案

这是一个有趣的想法。也许开始你应该添加的痕迹在你的扩展ByteArray的怎么看的FileReference#保存在内部()函数。

It's an interesting idea. Perhaps to start you should just add traces in your extended ByteArray to see how the FileReference#save() functions internally.

如果它有某种

while( originalByteArray.bytesAvailable ) 
  writeToSaveBuffer( originalByteArray.readByte() );

功能覆盖可能只是截断原来的​​缓冲区上的每个读像你说的,是这样的:

functionality the overrides could just truncate the original buffer on every read like you say, something like:

override function readByte() : uint {
  var b : uint = super.readByte();
  // Truncate the bytes (assuming bytesAvailable = length - removedBytes)
  length = length - bytesAvailable;
  return b;
}

在另一方面,如果现在工作我猜的原始字节数组不会算账的应用程序了。

On the other hand, if this now works I guess the original byte array would not be available afterwards in the application anymore.

(我没有带测试此我自己,截断可能需要比这个例子更多的工作)

(i havn't tested this myself, truncating might require more work than the example)

这篇关于FileReference.save()复制的ByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆