FileReference.save() 复制 ByteArray

发布于 2024-07-19 06:31:16 字数 572 浏览 3 评论 0 原文

我在使用 FileReference.save() 时遇到了内存问题。 我的Flash应用程序实时生成大量数据,需要将这些数据保存到本地文件中。 据我了解,Flash 10(相对于 AIR)不支持流式传输到文件。 但是,更糟糕的是 FileReference.save() 在保存之前复制了所有数据。 我正在寻找一种解决方法来解决内存使用量增加的问题,并考虑了以下方法:

如果我将 ByteArray 的自定义子类作为参数传递给 FileReference.save(),其中该 ByteArray 子类将覆盖所有 read*() 方法,该怎么办? 重写的 read*() 方法将等待我的应用程序生成一条数据,返回该数据并立即将其从内存中删除。 我知道将生成多少数据,因此我也可以重写 length/bytesAvailable 方法。

可能吗? 你能给我一些建议吗? 我创建了 ByteArray 的一个子类,为它注册了一个别名,将该子类的一个实例传递给 FileReference.save(),但不知何故 FileReference.save() 似乎将它视为 ByteArray 实例,而不是调用我的任何重写方法...

非常感谢您的帮助!

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:

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.

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...

Thanks a lot for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假面具 2024-07-26 06:31:17

这不是我以前尝试过的方法,但是您可以尝试将数据发送到 php 应用程序,该应用程序将处理将 ByteArray 保存到服务器,就像将图像保存到服务器一样,那么您可以使用 URLLoader.data 代替,使用类似这样的内容:

http://www.zedia.net/2008/sending-bytearray-and-variables-to-server-side-script-at-the-same-time/

It's not something I've tried before, but can you try sending the data out to a php application that would handle saving the ByteArray to the server, much like saving an image to the server, so then you'd use URLLoader.data instead, using something like this:

http://www.zedia.net/2008/sending-bytearray-and-variables-to-server-side-script-at-the-same-time/

你げ笑在眉眼 2024-07-26 06:31:17

这是一个有趣的想法。 也许首先您应该在扩展的 ByteArray 中添加跟踪,以查看 FileReference#save() 内部的功能。

如果它具有某种

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

功能,则覆盖可能会像您所说的那样在每次读取时截断原始缓冲区,例如:

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

另一方面,如果现在有效,我猜原始字节数组以后将不再在应用程序中可用。

(我自己没有测试过,截断可能需要比示例更多的工作)

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.

If it has some kind of

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文