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 7685465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:15:27+00:00 2026-05-31T19:15:27+00:00

So I’m working with a file format. The file format contains chunks of data…

  • 0

So I’m working with a file format. The file format contains chunks of data… So what I have is an array of List’s for the “chunks”. Those get added to when I add data to the class via a function.

Now, when I save the file, I need to ‘insert’ a chunk in the beginning. Now I know this may not make sense, but I need to add that chunk (which is blank) BEFORE I calculate the data offsets for the data types in the chunks. If I don’t, the data offsets get screwed up. After I insert that blank chunk, I then create a new byte[] array in which I copy the necessary data to, and then I “overwrite” the blank chunk that I inserted with the updated byte array.

The main reason why I need to do this is because the datachunk that I’m inserting contains offsets of the other data, so I need to create the offsets after everything has been added.

Basically what I have is this (only simplified):

    public struct SizeIndexPair {
        public int Size;
        public int Index;
    };

    public class Chunks {
        private Dictionary<int, SizeIndexPair> reserved;
        public List<List<byte> > DataChunks;

        ...

        public void Reserve(int ID, int size, int index) {
            SizeIndexPair sip;
            sip.Size = size;
            sip.Index = index;
            reserved.Add(ID, sip);
            List<byte> placeHolder = new List<byte>(size);
            DataChunks.Insert(index, placeHolder);
        }

        public void Register(int ID, byte[] data) {
            SizeIndexPair sip = reserved[ID];
            if (sip.Size != data.Length) 
                throw new IndexOutOfRangeException();
            for (int i = 0; i < data.Length; i++) {
                DataChunks[sip.Index][i] = data[i];
            }
        }
    };

(I’m using List(of byte) here because I might need to add extra data to an existing chunk)

I hope I’m making sense.

The problem with this approach is that I’m ‘doubling’ the array, which is eating up more memory. Plus the process of copying the data can slow down my app quite a bit, especially since the file typically contains alot of data.

Is there a better approach to this?

One thing that would have easily solved this is fixing the List and, instead of reserving/registering the array, I can simply access the array directly via a pointer. Is there a way to do this?

Thanks for your help.

  • 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-05-31T19:15:28+00:00Added an answer on May 31, 2026 at 7:15 pm

    If the goal is to insert a specific collection of bytes before the rest of the entries in your List<List<byte>> then you can use the overload:

    DataChunks.Insert(0, prefix);
    

    where 0 represents the index of the element in the collection to insert before and prefix is the value to insert.

    Then to get the resulting byte stream:

    foreach(byte b in DataChunks.SelectMany(c => c))
        Console.WriteLine(b); // replace with the method you use to write the `List of Lists of Bytes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.