C#中的随机访问流访问 [英] Random Access stream access in C#

查看:103
本文介绍了C#中的随机访问流访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我对项目有点困惑:具体来说,在旧时代创建像

引擎这样的数据库时',我本来会用一个流来包裹一个记录类

类,所以我可以在光盘上有一个记录文件,这样我就可以一直

直接跳到我想要的记录号码。简单的随机文件访问。


也许它们是固定长度的记录,我知道第n条记录是

(n *记录长度)文件。因此我可以直接跳到

(n *记录长度)字节并读出记录,因为我知道每个固定长度记录有多长时间。然后通过使用b-tree算法,我可以自己使用一个迷你数据库引擎。


问题是我如何实现记录管理类C#,使用

序列化,以便我可以直接跳转到特定记录?由于

所有内容都很好地包含在类和对象中。我们现在不使用指针

,也不知道大的类/结构在字节数方面是多少,我是如何直接跳到记录我想要在光盘上的记录文件? (或者在
记忆中等)。


可能我没有想到这一点,但我没看到

简单的方法。


如果有人能指出我正确的方向,我将非常感激。


如果我描述了这个问题,请大家给我一个喊叫,我会尽我所能

来澄清,


谢谢,

加里。

Hi All,

I am a bit stuck with a project: Specifically, when making a database like
engine in ''the old days'', I would have wrapped a record class with a stream
class, so I could have a file of records on disc, such that I could always
jump straight to the record number I wanted. Simple random file access.

Maybe they were fixed length records and I knew the n''th record was
(n*length of record) into the file. I could therefore jump straight to the
(n*length of record)th byte and read out the record, since I knew how long
each fixed length record was. Then by using a b-tree algorithm I could have
myself a mini-database engine.

The question is how do I implement the record management class in C#, using
serialization, so that I can jump straight to a specific record? Since
everything is wrapped up nicely in classes and objects. we don''t use pointers
much nowadays, nor know how ''big'' classes/structs are in terms of bytes, how
do I jump straight to the record I want in a file of records on disc? (or in
memory, etc).

It may be that I have not thought this through enough, but I don''t see an
easy way to do this.

If anybody could point me in the right direction I would be very grateful.

If I have described the problem badly give me a shout and I will do my best
to clarify,

Thanks,
Gary.

推荐答案

您有什么要求?我很好奇你为什么要写一个

数据库引擎。这些

天有各种现成的解决方案。这是什么目的?


-

HTH,


Kevin Spencer

Microsoft MVP

专业Numbskull


如果没有作品,请告诉我你的认证,

我会出示我的认证

* by *我的作品。


" Gary Bond" <嘎*** @ community.nospam>在消息中写道

新闻:5B ********************************** @ microsof t.com ...
What are your requirements? I''m curious as to why you want to write a
database engine. There are all sorts of ready-made solutions for this these
days. What is the purpose of this?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I''ll show my certification
*by* my works.

"Gary Bond" <Ga***@community.nospam> wrote in message
news:5B**********************************@microsof t.com...
大家好,

我对项目有点困惑:具体来说,当创建像
引擎这样的数据库''时过去'',我会用一个
流类包装一个记录课,所以我可以在光盘上有一个记录文件,这样我就可以随时直接跳到记录中我想要的号码。简单的随机文件访问。

也许它们是固定长度的记录,我知道第n条记录是
(n *记录长度)到文件中。因此我可以直接跳到
(n *记录长度)字节并读出记录,因为我知道每个固定长度记录有多长。然后通过使用b-tree算法,我可以自己拥有一个迷你数据库引擎。

问题是如何在C#中实现记录管理类,所有东西都很好地包含在类和对象中。我们现在很多都没有使用
指针,也不知道大的类/结构在字节方面如何,
我是如何直接跳到记录我想要在光盘上的记录文件? (或
在记忆中等)。

可能我没有想到这一点,但我没有看到一个简单的方法要做到这一点。

如果有人能指出我正确的方向,我会非常感激。

如果我描述了这个问题,那么就给我一个大喊大叫,我会做的我的
最好
澄清,
谢谢,
Gary。
Hi All,

I am a bit stuck with a project: Specifically, when making a database like
engine in ''the old days'', I would have wrapped a record class with a
stream
class, so I could have a file of records on disc, such that I could always
jump straight to the record number I wanted. Simple random file access.

Maybe they were fixed length records and I knew the n''th record was
(n*length of record) into the file. I could therefore jump straight to the
(n*length of record)th byte and read out the record, since I knew how long
each fixed length record was. Then by using a b-tree algorithm I could
have
myself a mini-database engine.

The question is how do I implement the record management class in C#,
using
serialization, so that I can jump straight to a specific record? Since
everything is wrapped up nicely in classes and objects. we don''t use
pointers
much nowadays, nor know how ''big'' classes/structs are in terms of bytes,
how
do I jump straight to the record I want in a file of records on disc? (or
in
memory, etc).

It may be that I have not thought this through enough, but I don''t see an
easy way to do this.

If anybody could point me in the right direction I would be very grateful.

If I have described the problem badly give me a shout and I will do my
best
to clarify,

Thanks,
Gary.



你好Vadym ,


非常感谢。我喜欢索引表的想法。排序


1)我想要第268条记录,所以我......

2)查看索引中的第268条记录,告诉我哪里我可以找到...

3)''正确文件中的第268条记录。


令人惊讶的是VB.Net有FileGetObject Function et al,我认为b $ b会完全按照我的意愿行事,但C#没有。 (我不是VB程序员

所以我不能肯定地说。)


但是,我很感激帮助。

问候,

加里。


" Vadym Stetsyak"写道:
Hi Vadym,

Many thanks for this. I like the index table idea. Sort of

1) I want the 268th record, so I ...
2) look up the 268th record in the index, which tell me where I can find ...
3) the 268th record in the ''proper file.

It is surprising that VB.Net has the FileGetObject Function et al, which I
think would do exactly what I want, but C# has not. (I am not a VB programmer
so I can''t say for sure).

However, I appreciate the help.
regards,
Gary.

"Vadym Stetsyak" wrote:
你好,加里!

GB>问题是如何在C#中实现记录管理类,
GB>使用序列化,以便我可以直接跳转到特定记录?
GB>因为所有东西都很好地包含在类和对象中。我们不是GB>现在使用指针,也不知道大的类/结构是如何在GB / gt;字节长度,如何直接跳转到文件中我想要的记录
GB>光盘上的记录? (或者在内存中等)。
IMO为了跳转到文件中记录,你必须设计一些记录元信息,它将描述文件中的记录(内存) )。
那就是你将在你的存储文件中引入某种结构。基本上,它看起来像具有记录长度和下一条记录偏移量的结构。

在内存中它看起来像这样

int recordLength
int nextRecordOffset
记录1
int recordLength
int nextRecordOffset
记录2

使用此结构,您可以在文件中迭代记录。迭代不是获取随机记录的最快方法,为此您可以引入索引表,具有固定大小,这样的索引的每个记录都可以包含偏移相应的记录。

HTH
-
此致,Vadym Stetsyak
www: http:// vadmyst。 blogspot



嗨凯文,

我是无法治愈的''必须找出工作原理''排序那个人,所以当我有时间在家时,我刚刚开始这样做作为一种爱好项目。

我的第一个兴趣是写一个B-Tree实现这样的领导

我这个。


白天我作为程序员工作,你是对的 - 我从来没有在

我能想到的任何生产意识。我们几乎只使用SQL Server

,我不认为我会尽快重写那个

8-)


所以答案真的只是一个爱好,发现类型的东西 -

我喜欢写代码!


欢呼,< br $>
Gary


" Kevin Spencer"写道:
Hi Kevin,
I am an incurable ''must find out how things work'' sort of person, and so I
just started doing this as a sort of hobby project when I have time at home.
My first interest was to write a B-Tree implementation and that sort of lead
me onto this.

By day I work as a programmer and you are right - I never would use this in
any production sense that I can think of. We use SQL Server virtually
exclusively, and I don''t think I will be trying to rewrite that anytime soon
8-)

So the answer really is just as a hobby, voyage of discovery type thing -
and I just love writing code!

cheers,
Gary

"Kevin Spencer" wrote:
您有什么要求?我很好奇你为什么要写一个
数据库引擎。这些天有各种现成的解决方案。这是什么目的?

-
HTH,

Kevin Spencer
微软MVP
专业Numbskull
<如果没有作品,请告诉我你的认证,
我将通过*我的作品展示我的认证。

Gary Bond <嘎*** @ community.nospam>在消息中写道
新闻:5B ********************************** @ microsof t.com。 ..
What are your requirements? I''m curious as to why you want to write a
database engine. There are all sorts of ready-made solutions for this these
days. What is the purpose of this?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I''ll show my certification
*by* my works.

"Gary Bond" <Ga***@community.nospam> wrote in message
news:5B**********************************@microsof t.com...
大家好,

我对项目有点困惑:具体来说,在旧时代创建像
引擎这样的数据库时,我会用一个
流类包装一个记录类,所以我可以在光盘上有一个记录文件,这样我就可以一直直接跳到我想要的记录号。简单的随机文件访问。

也许它们是固定长度的记录,我知道第n条记录是
(n *记录长度)到文件中。因此我可以直接跳到
(n *记录长度)字节并读出记录,因为我知道每个固定长度记录有多长。然后通过使用b-tree算法,我可以自己拥有一个迷你数据库引擎。

问题是如何在C#中实现记录管理类,所有东西都很好地包含在类和对象中。我们现在很多都没有使用
指针,也不知道大的类/结构在字节方面如何,
我是如何直接跳到记录我想要在光盘上的记录文件? (或
在记忆中等)。

可能我没有想到这一点,但我没有看到一个简单的方法要做到这一点。

如果有人能指出我正确的方向,我会非常感激。

如果我描述了这个问题,那么就给我一个大喊大叫,我会做的我的
最好
澄清,
谢谢,
Gary。
Hi All,

I am a bit stuck with a project: Specifically, when making a database like
engine in ''the old days'', I would have wrapped a record class with a
stream
class, so I could have a file of records on disc, such that I could always
jump straight to the record number I wanted. Simple random file access.

Maybe they were fixed length records and I knew the n''th record was
(n*length of record) into the file. I could therefore jump straight to the
(n*length of record)th byte and read out the record, since I knew how long
each fixed length record was. Then by using a b-tree algorithm I could
have
myself a mini-database engine.

The question is how do I implement the record management class in C#,
using
serialization, so that I can jump straight to a specific record? Since
everything is wrapped up nicely in classes and objects. we don''t use
pointers
much nowadays, nor know how ''big'' classes/structs are in terms of bytes,
how
do I jump straight to the record I want in a file of records on disc? (or
in
memory, etc).

It may be that I have not thought this through enough, but I don''t see an
easy way to do this.

If anybody could point me in the right direction I would be very grateful.

If I have described the problem badly give me a shout and I will do my
best
to clarify,

Thanks,
Gary.




这篇关于C#中的随机访问流访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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