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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:56:13+00:00 2026-05-15T12:56:13+00:00

I have a strange problem with object serialization. in the file documentation it states

  • 0

I have a strange problem with object serialization.
in the file documentation it states as following

The lead in starts with a 4-byte tag
that identifies a TDMS segment
(“TDSm”). The next four bytes are used
as a bit mask in order to indicate
what kind of data the segment
contains. This bit mask is referred to
as ToC (Table of Contents). Any
combination of the following flags can
be encoded in the ToC: The next four
bytes contain a version number (32-bit
unsigned integer), which specifies the
oldest TDMS revision a segment
complies with. At the time of this
writing, the version number is 4713.
The only previous version of TDMS has
number 4712. The next eight bytes
(64-bit unsigned integer) describe the
length of the remaining segment
(overall length of the segment minus
length of the lead in). If further
segments are appended to the file,
this number can be used to locate the
starting point of the following
segment. If an application encountered
a severe problem while writing to a
TDMS file (crash, power outage), all
bytes of this integer can be 0xFF.
This can only happen to the last
segment in a file. The last eight
bytes (64-bit unsigned integer)
describe the overall length of the
meta information in the segment. This
information is used for random access
to the raw data. If the segment
contains no meta data at all
(properties, index information, object
list), this value will be 0.

so i implemented as

class TDMsLEADIN {
public:
    char   Signature[4];    //TDSm
    __int32     Toc;
    unsigned __int32     vernum;
    unsigned __int64  nextSegmentOff;
    unsigned __int64  rawDataOff;
};
fread(&leadin,sizeof(TDMsLEADIN),1,f);

then i got signature=”TDsm”, TOc=6, vernum=4712 as expected.
nextSegmentOff=833223655424, rawDataOff=8589934592 but expected both of nextSegmentOff and rawDataOff=194

then i break the class into two parts, and read two two parts seperately

class TDMsLEADIN {
public:
    char   Signature[4];    //TDSm
    __int32     Toc;
    unsigned __int32     vernum;

};
class TDMsLeadINend{
public:
    unsigned __int64 nextSegmentOff;
    unsigned __int64 rawDataOff;
};
    fread(&leadin,sizeof(TDMsLEADIN),1,f);
    fread(&leadin2,sizeof(TDMsLeadINend),1,f);

then i got nextSegmentOff ,rawDataOff as expected=194.
my question is what is wrong with the original code? why it works when i break it into two parts? i tried unsigned long long instead of unsigned __int64, but still the same result.
it is quite strange.

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-05-15T12:56:14+00:00Added an answer on May 15, 2026 at 12:56 pm

    You seem to be just reading and writing the binary data in the struct directly.

    Generally the compiler will align structure data for performance, so when it’s a single struct there’s a hidden 32-bit pad between vernum and nextSegmentOff to align nextSegmentOff. When it’s split into two structures there’s no such extra padding and you’re reading four bytes of padding and four bytes of real data into nextSegmentOff.

    You can test this by comparing the sizeof(TDMsLEADIN [second version]) + sizeof(TDMsLeadINend) to sizeof(TDMsLEADIN [first version])

    The standard way to serialize data is to serialize each underlying piece individually rather than relying on the layout of a class or structure as that can change by compiler without notice.

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

Sidebar

Ask A Question

Stats

  • Questions 435k
  • Answers 435k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Locate the .DSK file for any project it is trying… May 15, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer Current version of LINQ to SQL does not generate a… May 15, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer You have to just put this code into "cellForRowAtIndexPath" For… May 15, 2026 at 3:36 pm

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.