简体   繁体   English

FileReference.save()复制ByteArray

[英]FileReference.save() duplicates ByteArray

I've encountered a memory problem using FileReference.save(). 我在使用FileReference.save()时遇到了内存问题。 My Flash application generates of a lot of data in real-time and needs to save this data to a local file. 我的Flash应用程序实时生成大量数据,需要将这些数据保存到本地文件中。 As I understand, Flash 10 (as opposed to AIR) does not support streaming to a file. 据我了解,Flash 10(而不是AIR)不支持流式传输到文件。 But, what's even worse is that FileReference.save() duplicates all the data before saving it. 但是,更糟糕的是FileReference.save()在保存之前复制所有数据。 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. 如果我将ByteArray的自定义子类作为参数传递给FileReference.save(),该ByteArray子类将覆盖所有read *()方法,该怎么办。 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. 重写的read *()方法将等待我的应用程序生成一条数据,返回此数据,然后立即将其从内存中删除。 I know how much data will be generated, so I could also override length/bytesAvailable methods. 我知道将生成多少数据,因此我也可以覆盖length / bytesAvailable方法。

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(),但是不知何故,FileReference.save()似乎将其视为ByteArray实例,并且没有调用任何我覆盖的方法...

Thanks a lot for any help! 非常感谢您的帮助!

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: 这不是我之前尝试过的事情,但是您可以尝试将数据发送到php应用程序中,该应用程序可以将ByteArray保存到服务器中,就像将图像保存到服务器中一样,因此您可以使用URLLoader.data代替,使用类似以下内容的代码:

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

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. 也许一开始,您应该在扩展的ByteArray中添加跟踪,以查看FileReference#save()在内部的功能。

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) (我自己没有测试过,截断可能需要比示例更多的工作)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM