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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:43:20+00:00 2026-05-15T01:43:20+00:00

The following function writes a struct to a file. #define PAGESIZE sizeof(BTPAGE) #define HEADERSIZE

  • 0

The following function writes a struct to a file.

#define PAGESIZE  sizeof(BTPAGE)
#define HEADERSIZE 2L

    int btwrite(short rrn, BTPAGE *page_ptr)
    {
        long addr;
        addr = (long) rrn * (long) PAGESIZE + HEADERSIZE;
        lseek(btfd, addr, 0);
        return (write(btfd, page_ptr, PAGESIZE));
    }

The following is the struct.

typedef struct {
    short keycount;             /* number of keys in page   */
    int  key[MAXKEYS];              /* the actual keys      */
    int  value[MAXKEYS];            /* the actual values        */
    short child[MAXKEYS+1];     /* ptrs to rrns of descendants  */
} BTPAGE;

What would happen if I changed the struct to a class, would it still work the same?

If I added class functions, would the size it takes up on disk increase?

  • 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-15T01:43:21+00:00Added an answer on May 15, 2026 at 1:43 am

    There’s a lot you need to learn here.

    • First of all, you’re treating a structure as an array of bytes. This is strictly undefined behavior due to the strict aliasing rule. Anything can happen. So don’t do it. Use proper serialization (for example via boost) instead. Yes, it’s tedious. Yes, it’s necessary.
    • Even if you ignore the undefinedness, and choose to become dependant on some particular compiler implementation (which may change even in the next compiler version), there’s still reasons not to do it.
      • If you save a file on one machine, then load it on another, you may get garbage, because the second machine uses a different float representation, or a different endianness, or has different alignment rules, etc.
      • If your struct contains any pointers, it’s very likely that saving them verbatim then loading them back will result in an address that doesn’t not point to any meaningful place.
    • Typically when you add a member function, this happens:
      • the function’s machine code is stored in a place shared by all the class instances (it wouldn’t make sense to duplicate it, since it’s logically immutable)
      • a hidden “this” pointer is passed to the function when it’s called, so it knows which object it’s been called on.
      • none of this requires any storage space in the instances.
    • However, when you add at least one virtual function, the compiler typically needs to also add a data chunk called a vtable (read up on it). This makes it possible to call different code depending on the current runtime type of the object (aka polymorphism). So the first virtual function you add to the class likely does increase the object size.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • 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 I've been thinking about the same combo as well. PyAMF… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer The documentation for StyleCop Rule SA1101 actually mentions this: A… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer The idea from my answer to your previous question was… May 16, 2026 at 4:00 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

Related Questions

I get an error on line 6 (initialize my_foo to foo_init) of the following
The linker is reporting multiply defined errors for an inline function. I have the
This is my first ever attempt at writing a recursive function in c. The
i have a list of struct list who have a detail of stuff. i
Suppose we have the following problem - we want to read a set of
this might be a bit long so my apologies. consider the following code (i've
I found the following code which is working well for a time sheet calculator
I have a simple service that does approximately the following: An HTTP client connects
I start with the following list s and bitmask b : s = ['baa',
currently I have following code: home.php <form name='myformname' id='myformid'> <input type='text' name='mytext1' value='abc'> <input

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.