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

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

问题描述

我在使用 FileReference.save() 时遇到了内存问题.我的 Flash 应用程序实时生成大量数据,需要将这些数据保存到本地文件.据我了解,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 子类将覆盖所有 read*() 方法.重写的 read*() 方法将等待我的应用程序生成一条数据,返回这条数据并立即将其从内存中删除.我知道将生成多少数据,因此我还可以覆盖 length/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#save() 内部如何运行.

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天全站免登陆