Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is is a data <em>tree</em>, or a full <em>graph</em> - i.e. are there any circular references? If not, <a href="http://code.google.com/p/protobuf-net/" rel="nofollow noreferrer">protobuf-net</a> is a high-performance binary <em>tree</em> serializer. It supports streaming of enumerable items (so you can skip records, etc - rather than buffer everything), but to <em>efficiently</em> seek to a random element I expect you'd need some kind of index.</p> <p>Read/write is <strong>VERY</strong> hard for a single file; in particular, writing may require moving lots more of the disk than you expect... reading is also tricky and might require synchronization. It would be easier to use separate files...</p> <hr> <p>Example of skipping early items; I could probably add a helper method, but the <code>TryDeserializeWithLengthPrefix</code> method will work... the key point being to watch that between serialization and deserialization we only create one extra object.</p> <pre><code>using System; using System.IO; using System.Threading; using ProtoBuf; [ProtoContract] class Foo { static int count; public static int ObjectCount { get { return count; } } public Foo() { // track how many objects have been created... Interlocked.Increment(ref count); } [ProtoMember(1)] public int Id { get; set; } [ProtoMember(2)] public double Bar { get; set; } } static class Program { static void Main() { MemoryStream ms = new MemoryStream(); Random rand = new Random(); for (int i = 1; i &lt;= 5000; i++) { Foo foo = new Foo { Bar = rand.NextDouble(), Id = i }; Serializer.SerializeWithLengthPrefix(ms, foo,PrefixStyle.Base128, 1); } ms.Position = 0; // skip 1000 int index = 0; object obj; Console.WriteLine(Foo.ObjectCount); Serializer.NonGeneric.TryDeserializeWithLengthPrefix( ms, PrefixStyle.Base128, tag =&gt; ++index == 1000 ? typeof(Foo) : null, out obj); Console.WriteLine(Foo.ObjectCount); Console.WriteLine(((Foo)obj).Id); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload