最好的方式来储存在C#长二进制(最多512位) [英] Best way to store long binary (up to 512 bit) in C#

查看:198
本文介绍了最好的方式来储存在C#长二进制(最多512位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出存储大量的二进制(超过96位)数在C#中的最佳方式。

I'm trying to figure out the best way to store large binary (more than 96 bit) numbers in C#

我建立的应用程序,会自动分配工人轮班。移位可以是短至15分钟(但这可能是即使在未来更小)。为了避免工人的双重预订,我打算有他们的日常时间的二进制图:等于块分离24小时(15分钟),每块有一个标志(0免费,1为忙碌)
因此,当我们试图给另一个转移到工人,我们可以用换挡的时间工人日报可用性二进制比较。简单和易于决定。

I'm building application that will automatically allocate workers for shifts. Shifts can be as short as 15 minutes (but this might be even smaller in the future). To avoid double-booking of workers, I plan to have binary map of their daily time: 24 hours separated in equal chunks (15 minutes) and every chunk has a flag (0 for free, 1 for busy) So when we try to give another shift to a worker, we can do binary comparison of workers daily availability with shift's time. Simple and easy to decide.

但是C#长仅允许具有高达64位,并与当前设置我需要至少96位(24小时* 60分钟/每周期15分钟)。
这将重新presentation必须是内存友好,因为将有大约在同一时间运行一百万的对象。

But C# long only allows to have up to 64 bit, and with the current set up I need at least 96 bits (24 hours * 60 minutes / 15 minutes per period). This representation must be memory friendly, as there will be about a million objects operated at a time.

很少有其他的选择我认为是:

Few other options i considered:


  • 字符串。内存大户,实行逐位运算并不简单

  • 位的数组。但据我所知,C#没有位类型

  • 无符号整数数组。每个阵列重新presents只有一天的一部分。最好我能想到的

任何其他建议?

在此先感谢!

推荐答案

您可以使用和字节数组。我不认为任何语言支持位阵列,作为一个字节是最小的可寻址的内存块。其他选项是布尔值数组,但每个布尔我相信还是会以存储为一个字节,所以就被浪费的内存,但它可能是更容易的工作。这要看你要多少天的工作。你也可以只存储移位的开始和结束,并使用其他手段来找出是否有重叠的时间表。这将可能使最有意义,而且是最简单的调试。

You could use and array of bytes. I don't think any language supports an array of bits, as a byte is the smallest addressable piece of memory. Other options are an array of booleans, but each boolean I believe is stored as a byte anyway, so there would be wasted memory, but it might be easier to work with. It really depends on how many days you are going to work with. You could also just store the start and end of the shift and use other means to figure out if there are overlapping schedules. This would probably make the most sense, and be the easiest to debug.

这篇关于最好的方式来储存在C#长二进制(最多512位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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