大型可变字节数组在二郎山 [英] Large mutable byte array in Erlang

查看:87
本文介绍了大型可变字节数组在二郎山的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我写在二郎一个简单的Minecraft服务器应用程序,我现在关心的是如何有效地存储和修改数据块的问题。
对于那些不知道我的世界的内部谁也:我需要高达32KB的大小了很多的二进制文件(100-1000)存储在内存中。直到此时Erlang的内置二进制代码就足够了。但是,服务器具有读取和改变这些二进制文件的一些字节(通过其ID)很多时候,我不想将它们复制周围所有的时间。结果
一个不错的特点将是自/至Erlang的标准二进制文件导入和导出。

As I am writing a simple Minecraft server application in Erlang, I am now concerned with the question of how to efficiently store and modify chunk data. For those who don't know about Minecraft's internals: I need to store a lot of binaries (100-1000) of up to 32kB size in memory. Until this point Erlang's builtin binaries are sufficient. But the server has to read and change some bytes (by their id) in these binaries quite often and I don't want to copy them around all the time.
A nice to have feature would be import and export from/to Erlang's standard binaries.

有没有二郎延长或数据库或任何我可以用这个?

Is there any Erlang extension or database or whatever I could use for this?

推荐答案

由于二进制文件是只读的,我能想到的下列方法(假设你期望的变化率高):

Since binaries are read-only, I can think of the following approaches (assuming you expect high rate of changes):


  1. 使用树状结构中的叶子比较小一成不变的二进制文件。在这种情况下,当你修改你的数据,你只需要重新创建小叶二进制+到根所有节点。假设变化是地方在一定的位置,我想,你可以用OCTO树开始。

  2. 变化
  3. 使用大二进制+列表(这可能是功能简单的列表)。当您需要修改的世界,只需添加新功能列表。当有人问世界的状态,以基本的二进制和应用列表中的所有变化。不时南瓜的所有变化和prepare一个新的基线状态的二进制文件。这可以用previous办法(树对在叶子二进制/的变化)相结合。

  4. 将可变世界管理到外部code。您可以使用 NIFS 或的端口的。我想,这将是最快的方式。另外,我认为这将是比较容易实现的。 API的第一个版本可以像世界一样简单:新的(X,Y,Z) - GT; REF();世界:得到(参考,X,Y,Z);世界:集(参考,X,Y,Z,值);

  1. Use tree-like structure with relatively small immutable binaries in the leafs. In that case, when you modify you data, you only need to re-create small leaf binary + all nodes up to the root. Assuming that changes are "local" to some position, I think, you can start with octo-tree.
  2. Use "big" binaries + list of changes (that could be as simple list of functions). When you need to modify world, just add new function to the list. When someone asks for the world state, take base binary and apply all changes from the list. From time to time "squash" all changes and prepare a new baseline state binary. This could be combined with previous approach (tree with pairs of binary/changes in the leafs).
  3. Move mutable world management to the external code. You can use NIFs or Ports. I think, that would be the fastest way. Also, I think it would be relatively easy to implement it. The first version of API could be as simple as world:new(X, Y, Z) -> ref(); world:get(Ref, X, Y, Z); world:set(Ref, X, Y, Z, Value);

这篇关于大型可变字节数组在二郎山的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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