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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:58:30+00:00 2026-06-15T07:58:30+00:00

I have a binary file with the following structure: +———+——-+——+—-+——-+ | Header | Obj1

  • 0

I have a binary file with the following structure:

+———+——-+——+—-+——-+
| Header | Obj1 | Obj2 | … | Index |
+———+——-+——+—-+——-+

The Index is a vector of variable size depending on the number of objects and stores the file position for each object. E.g.

vector<size_t> index;

index.push_back(ofs.tellp());
write(reinterpret_cast<char *> obj, sizeof(obj));

Also the files are pretty big (1Gb+).

I’d like to put the index just after the header, so it’s faster to read. Can I do this without having to copy and write all the objects twice? Thanks.

  • 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-15T07:58:31+00:00Added an answer on June 15, 2026 at 7:58 am

    You have two solutions:

    • use a separate file for the index
    • move on to a chunk based design

    The first one is relatively obvious, so I’ll only outline the second one: the problem here is that your index size depends on the number of objects you stream. It need not be so.

    A solution would be to skip a definite amount of space (later used for indexing), stream the objects (up to N), record where you are, get back to the index to write it down, and then move on to the next chunk (note: the chunks are not fixed size here).

    Example of layout:

    - Step 1: skip index space and start streaming objects
    
    | Header | <unused space for now> | Obj 1 | Obj 2   | O3 | ... Obj N |
    
    
    - Step 2: after writing N objects write the index,
              record the offset,
              start a new chunk
    
    | Header | I1 | ... | IN | Offset | Obj 1 | Obj 2   | O3 | ... Obj N | <unused sp
    

    Your index is thus built as a linked list of fixed size chunks (N) interleaved in the middle of your storage.

    Note: a third solution would be to use a simple SQLite file and let it index for you…

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

Sidebar

Related Questions

We have a binary file from which we have identified the following dates (as
I am having following issue with reading binary file in C. I have read
i have a binary file which has 4 KB of header information and then
Ok, so I currently have a binary file containing an unknown number of structs
I have some code similar to the following for downloading a binary file. My
I have a floating point number stored in a binary file 0.9999833107. When I
i want to read\write a binary file which has the following structure: The file
I have a following directory structure, I also have this make file that works
i have a binary file with following format : [N bytes identifier & record
I have a make file of, more or less, the following structure that compiles

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.