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

  • SEARCH
  • Home
  • 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 8975739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:57:23+00:00 2026-06-15T18:57:23+00:00

I am working with big multidimensional byte arrays (~500mb per array, like, an array

  • 0

I am working with big multidimensional byte arrays (~500mb per array, like, an array with dimensions of [8,8192,8192]) and I’d like to read and write them into file for storage.

I tried using BinaryFormatter but is very slow (takes minutes to do).

I tried using BinaryWriter but it only takes in a single dimensional array. Now, in C, there was no problem passing multi-dimensional array as single-dimensional. In C#, from what I see, I have two options:

  • Allocate another chunk of memory for single-dimensional array, copy data into it with for loops, then write this array into file using BinaryWriter
  • Using for loops, write each individual byte into file using BinaryWriter

Obviously it would be much faster if i’d just use byte[] everywhere and instead of using myarray[i,j] use myarray[i+j*myarray_width] but that would require rewrite of whole class just for purpose of easier working of one set of I/O functions (Save/Load).

There’s gotta be a better way.

  • 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. Editorial Team
    Editorial Team
    2026-06-15T18:57:25+00:00Added an answer on June 15, 2026 at 6:57 pm

    When it comes to fast serialization, unsafe code might come in handy. There are two techniques that can help here:

    1. Do a memcpy from your byte[,] to a fresh byte[] that you can pass to FileStream.Write. This requires, of course, a temporary doubling of storage space and some copying. You could split this work into 64KB chunks, though.
    2. PInvoke to the unmanaged WriteFile and pass it the FileStream.SafeHandle value. WriteFile takes an arbitrary pointer so you can directly write out your byte[,] (converted into a void*).

    Option 2 is maximally fast (“zero-copy”).

    Sidenote: Unsafe code comes in handy whenever you need to reinterpret bytes. This capability leads to some nice abstractions in C. Fortunately, C# has that capability, too.

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

Sidebar

Related Questions

I'm working with an open-source CMS that uses some very big multi dimensional arrays/objects.
I'm working on an big excel-addin with many modules. I need to export them
I am working on big application build using ASP.NET which was started 1.5 years
i'm working on a big python project, and i'm really sick if .pyc and
I'm working on a big c++ project and change code from other people. During
We are working on a big project. During our development we faced with a
I'm working on a big project for embedded systems. The project is a library
I'm working on a big flash site with lots of component swfs and a
I'm working on a big Qt application with multiple widgets which are quite complex.
I'm currently working with a big container that i need to iterater over an

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.