Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 60965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:14:40+00:00 2026-05-10T18:14:40+00:00

I have a class that I need to binary serialize. The class contains one

  • 0

I have a class that I need to binary serialize. The class contains one field as below:

private T[,] m_data; 

These multi-dimensional arrays can be fairly large (hundreds of thousands of elements) and of any primitive type. When I tried standard .net serialization on an object the file written to disk was large and I think .net is storing a lot of repeated data about element types and possibly not as efficiently as could be done.

I have looked around for custom serializers but have not seen any that deal with multi-dimensional generic arrays. I have also experimented with built-in .net compression on a byte array of the memory stream following serializing with some success, but not as quick / compressed as I had hoped.

My question is, should I try and write a custom serializer to optimally serialize this array for the appropriate type (this seems a little daunting), or should I use standard .net serialization and add compression?

Any advice on the best approach would be most appreciated, or links to resources showing how to tackle serialization of a multi-dimensional generic array – as mentioned existing examples I have found do not support such structures.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:14:41+00:00Added an answer on May 10, 2026 at 6:14 pm

    Here’s what I came up with. The code below makes an int[1000][10000] and writes it out using the BinaryFormatter to 2 files – one zipped and one not.

    The zipped file is 1.19 MB (1,255,339 bytes) Unzipped is 38.2 MB (40,150,034 bytes)

            int width = 1000;         int height = 10000;         List<int[]> list = new List<int[]>();         for (int i = 0; i < height; i++)         {             list.Add(Enumerable.Range(0, width).ToArray());         }         int[][] bazillionInts = list.ToArray();         using (FileStream fsZ = new FileStream('c:\\temp_zipped.txt', FileMode.Create))         using (FileStream fs = new FileStream('c:\\temp_notZipped.txt', FileMode.Create))         using (GZipStream gz = new GZipStream(fsZ, CompressionMode.Compress))         {             BinaryFormatter f = new BinaryFormatter();             f.Serialize(gz, bazillionInts);             f.Serialize(fs, bazillionInts);         } 

    I can’t think of a better/easy way to do this. The zipped version is pretty damn tight.

    I’d go with the BinaryFormatter + GZipStream. Making something custom would not be fun at all.


    [edit by MG] I hope you won’t be offended by an edit, but the uniform repeated Range(0,width) is skewing things vastly; change to:

            int width = 1000;         int height = 10000;         Random rand = new Random(123456);         int[,] bazillionInts = new int[width, height];         for(int i = 0 ; i < width;i++)             for (int j = 0; j < height; j++)             {                 bazillionInts[i, j] = rand.Next(50000);             } 

    And try it; you’ll see temp_notZipped.txt at 40MB, temp_zipped.txt at 62MB. Not so appealing…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 71k
  • Answers 72k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer WPF projects will - by default - generate an entry… May 11, 2026 at 1:29 pm
  • added an answer Here is the deal: in machine learning problems, you typically… May 11, 2026 at 1:29 pm
  • added an answer I don't think you can have properties of array types.… May 11, 2026 at 1:29 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.