在Lua中快速序列化/反序列化表(无递归) [英] Fast serialize / deserialize table (no recursion) in Lua

查看:193
本文介绍了在Lua中快速序列化/反序列化表(无递归)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Lua 5.2.我正在接收大小为800,000的大表(一维数组).我想快速转储这些表.我在Wiki上找到了标题为将表保存到文件" 的文章,并使用了它,但发现没有达到标记.使用此方法(即table.save(table, filename))保存的示例表在我的DropBox中共享

I am using Lua 5.2. I am receiving large tables (1-dimensional array) of size 800,000. I want to dump these tables quickly. I found an article on wiki titled Save Table To File and used it but found not up to the mark. A sample table saved using this method, i.e., table.save(table, filename) is shared in my DropBox here. (File is too large to put here. 8MB approx)

由于我最关心的是速度,因此我准备采用二进制序列化(如果存在).

Since my primary concern is speed, I am ready to adopt binary serialization if such exists.

推荐答案

您是否绑定到Lua 5.2? 5.3引入了按位运算符和内置的二进制打包/拆包操作(请参见《 Lua编程》(第4版)的第13章位和字节").第15章数据文件和序列化"中还提供了用于序列化表的特定算法和建议.这些章节将是您正确实施的最佳信息来源.

Are you bound to Lua 5.2? 5.3 introduced bitwise operators and built-in binary pack/unpack operations (see chapter 13, "Bits and Bytes", of Programming in Lua, 4th edition). There are also specific algorithms and recommendations for serializing tables in chapter 15, "Data Files and Serialization". These chapters will be your best source of information for a proper implementation.

这篇关于在Lua中快速序列化/反序列化表(无递归)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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