code_junkie

C# - Optimising binary serialization for multi-dimensional generic arrays

Nov 11th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. private T[,] m_data;
  2.  
  3. int width = 1000;
  4. int height = 10000;
  5. List<int[]> list = new List<int[]>();
  6. for (int i = 0; i < height; i++)
  7. {
  8. list.Add(Enumerable.Range(0, width).ToArray());
  9. }
  10. int[][] bazillionInts = list.ToArray();
  11. using (FileStream fsZ = new FileStream("c:\temp_zipped.txt", FileMode.Create))
  12. using (FileStream fs = new FileStream("c:\temp_notZipped.txt", FileMode.Create))
  13. using (GZipStream gz = new GZipStream(fsZ, CompressionMode.Compress))
  14. {
  15. BinaryFormatter f = new BinaryFormatter();
  16. f.Serialize(gz, bazillionInts);
  17. f.Serialize(fs, bazillionInts);
  18. }
  19.  
  20. int width = 1000;
  21. int height = 10000;
  22. Random rand = new Random(123456);
  23. int[,] bazillionInts = new int[width, height];
  24. for(int i = 0 ; i < width;i++)
  25. for (int j = 0; j < height; j++)
  26. {
  27. bazillionInts[i, j] = rand.Next(50000);
  28. }
Add Comment
Please, Sign In to add comment