Random Access stream access in C#

J

Jon Skeet [C# MVP]

At any rate, it seemed like you had, for the most part, taken over the
topic, and I was merely making mention of the fact that, if he is accustomed
to using pointers, he might be better off to work with C#, which I prefer
for several reasons, possibly the least of which (but in my case absolutely
necessary at times) is pointer availability. I didn't want to go into gory
detail about it.

Right. I think what I'm very keen on making sure of is that Gary
realises that most "normal" uses of pointers in C are achieved using
either indexes into arrays, or just normal references.

Hopefully between us we've got that point and your point that pointers
*are* available in C#, across now :)
 
J

Jon Skeet [C# MVP]

Here I can find the length of bytes that represent the serialized object,
via putting it into a MemoryStream first, and I don't have to make
assumptions about the size of the underlying primitives/size of strings etc.
This was the bit that I could not 'get'. (Is there an easier way of doing
this?).

I don't know of an easier way, no. It's fairly easy to encapsulate
though.
So, I can save lots of different size objects, into one storage file, and
get them back out again via the usual deserialize, since I know where they
start in the file, (assuming I keep track of their start positions via an
index of some description).

Yes - although that makes it a pain in terms of removing records, as
you noted later.
but, at least your comments sort of broke my mental deadlock. So, what I am
going to do is:

1) See if I can really understand what is happening when you serialize
something, and maybe implement my own scheme to get 'stuff' into/out of a
stream, (ref Jon's comment on serialization above)

Good plan. One of the things about serialization is that the type
information is embedded in the data - obviously that's somewhat
inefficient if you already know the type!
2) Actually write some code to to implement a variable record manager class
along these lines.

If you definitely need variable length records, that's fair enough.
Does your data definitely not work as fixed length records?
Could I come back with some code in the future, (might be a while), on this
topic for your comments?, or is there somewhere more appropriate if no?

Here is absolutely fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top