KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a structure holding 3d co-ordinates in 3 ints. In a test I've put together a List<> of 1 million random points and then used Binary serialization to a memory stream. The memory stream is coming in a ~ 21 MB - which seems very inefficient as 1000000 points * 3 coords * 4 bytes should come out at 11MB minimum Its also taking ~ 3 seconds on my test rig. Any ideas for improving performance and/or size? (I don't have to keep the ISerialzable interface if it helps, I could write out directly to a memory stream) EDIT - From answers below I've put together a serialization showdown comparing BinaryFormatter, 'Raw' BinaryWriter and Protobuf using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using ProtoBuf; namespace asp_heatmap.test { [Serializable()] // For .NET BinaryFormatter [ProtoContract] // For Protobuf public class Coordinates : ISerializable { [Serializable()] [ProtoContract] public struct CoOrd { public CoOrd(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } [ProtoMember(1)] public int x; [ProtoMember(2)] public int y; [ProtoMember(3)] public int z; } internal Coordinates() { } [ProtoMember(1)] public List<CoOrd> Coords = new List<CoOrd>(); public void SetupTestArray() { Random r = new Random(); List<CoOrd> coordinates = new List<CoOrd>(); for (int i = 0; i < 1000000; i++) { Coords.Add(new CoOrd(r.Next(), r.Nex
Tags (comma-separated)
Save Edits
Cancel