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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:15:07+00:00 2026-05-23T03:15:07+00:00

Say I have 1 million structs, each containing integers, doubles, strings, and other structs,

  • 0

Say I have 1 million structs, each containing integers, doubles, strings, and other structs, something like:

struct s1 {
    int f1;
    long f2;
    char* f3;
};

struct s2 {
    struct s1* f1;
    double f2;
};

How can I save these to a file in binary format, then look up and load them from that file, on platforms different from the one the executable was compiled on, without worrying about endianness, float representation and other platform-specific gotchas?

The reason for preferring a binary format is mainly size of the resulting file. If integers alone look like “32435” and I have millions of them, the extra 3 bytes per integer would add quite a bit of size to the file.

  • 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-23T03:15:07+00:00Added an answer on May 23, 2026 at 3:15 am

    “platforms different from the one the executable was compiled on”

    How different from the one the executable was compiled on? Do you need to support platforms that use non-IEEE floats? Platforms that use non-ASCII characters? Platforms that use non-8-bit bytes?

    If you insist on binary, and insist on doing it yourself, probably your best bet is to define that in the storage format, int and long will each be stored as a sequence of 4 bytes, little-endian (or big-endian, but pick one and stick to it regardless of platform), containing exactly 8 significant bits per byte. double will be an IEEE double likewise. Pointers introduce a whole world of hurt, the storage format must attach a unique identifier to each instance of s1, and then a pointer to s1 can be stored as an id value, and looked up as part of deserialization.

    Different platforms can then decide what types they want to use for each of the storage types (so for example if int is only 16 bits on a give platform, it will just have to use long for both the int and long types. For this reason, you should give them domain-specific pseudonyms). Beware that it’s impossible to avoid loss of precision in double values when converting to and from incompatible representations, since they might not have the same number of significant bits.

    For text, non-ASCII platforms will have to include code to serialize their own text format to ASCII, and to deserialize ASCII to native text. Strictly speaking, you should also avoid using any characters in the text that aren’t in the C basic character set, since they might not be representable at all on the target. You can make a similar decision whether you’re willing to count on target platforms to support Unicode in some way — if so then UTF-8 is a reasonable interchange format for text.

    Finally, for each struct on each platform, you can either:

    1. write (or perhaps auto-generate) code to serialize it, and code to deserialize it, or:
    2. make yourself a domain-specific language to define the structures, and a parser/interpreter that will serialize and deserialize according to that definition.

    Sounds like a lot of work to me, though, to do something that’s been done before.

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

Sidebar

Related Questions

Lets say I have a table containing several hundred million rows that looks something
Let's say I have a AWS SimpleDB domain with around 3 million items, each
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say I have 50 million features, each feature comes from disk. At the beggining
Lets say I have a million people objects that, when evaluated using person1.Matches(person2); return
Say you have a MySQL 5.0 MyISAM table with 100 million rows, with one
Say if I have a large dataset, the table has well over a million
Lets say have this immutable record type: public class Record { public Record(int x,
It's been asked a million times, its like this . Say Invoice is the
I have a class that has an internal list of other objects like so:

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.