简体   繁体   English

C#uint64 —存储数据?

[英]C# uint64 — Store data?

Is there a better way to store numerical data in an uint64 other than using x digits for one piece, y digits for other stuff? 除了将x位数字用于一件,将y位数字用于其他东西之外,是否有更好的方法将数字数据存储在uint64中? (20 digits total to work with) (总共20位数字)

I am trying to store information about an object without having the overhead of making a struct or class. 我正在尝试存储有关对象的信息,而没有制作结构或类的开销。 I need to get/set as fast as possible with minimal overhead. 我需要以最小的开销尽快获取/设置。

So, as far as I know voxels coding. 因此,据我所知,体素编码。 If you want to store "blocks" data that is defined one by one then you can use interval tree , where the key of each node is the start of a run and the value is the coordinate of the run. 如果要存储一个一个定义的“块”数据,则可以使用时间间隔树 ,其中每个节点的键是运行的起点,而值是运行的坐标。 Implemntation example . 象征例子

Also, you NEVER store single block as class but SET of blocks for example block 3x3 can be done as: 另外,您永远不要将单个块存储为类,但是可以通过以下方式设置块的设置,例如块3x3:

在此处输入图片说明

as you see I just coded data position of 9 blocks in two bits This is simplified method for which data size is not the problem but fast implementation of iteration that needs form you some algorithm. 如您所见,我只是将两位的9个块的数据位置编码了。这是一种简化的方法,其数据大小不是问题,而是快速迭代的实现,需要某种算法。

Before you even start play with Voxels read these 在开始使用Voxels之前,请阅读以下内容

Let's Make a Voxel Engine 让我们制作一个体素引擎

Damn, Voxel Data is BIG 该死,体素数据很大

Voxel engines are everywhere… 体素引擎无处不在...

Voxel Engine – Data Storage Voxel引擎–数据存储

Internet is full of answeres, but these will give your information that you need. 互联网上有很多答案,但是这些都会为您提供所需的信息。 Also keyword that I think you were mising is VOXEL 我认为您在误解的另一个关键字是VOXEL

If using uint64 or ulong is not a fixed requirement, I suggest you use the BigInteger class . 如果使用uint64ulong不是固定要求,建议您使用BigInteger类 It was designed to efficiently store arbitrarily-large numbers. 它旨在有效地存储任意数量的数字。

Is it efficient? 有效率吗? If you decompile the code, you'll see that they store an array of bits internally to manage the number. 如果您对代码进行反编译,则会看到它们在内部存储了一个位数组来管理数字。 That is, with N bits, it stores a number up to 2^N - 1 . 也就是说,使用N位,它存储的数字最大为2^N - 1

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

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