Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (20 points) Produce an inefficient struct in C that wastes (at least) 77.78% of the space required for the struct. For example, the struct

3. (20 points) Produce an inefficient struct in C that wastes (at least) 77.78% of the space required for the struct.

For example, the struct typedef struct { uint16_t a; uint32_t b; uint16_t c; } S1; takes 12 bytes, but typedef struct { uint16_t a; uint16_t c; uint32_t b; } S2; only requires 8 bytes. Thus it is wasting (12 8) = 4 bytes, or 50% of the space required by the struct.

Ive provided a program on the next page that can be used to compute the inefficiency of struct packing. 1 #include #include typedef struct { uint16_t a; uint32_t b; uint16_t c; } S1; typedef struct { uint16_t a; uint16_t c; uint32_t b; } S2; int main() { double size1 = sizeof(S1); double size2 = sizeof(S2); printf("size: %lu ",sizeof(S1)); printf("size: %lu ",sizeof(S2)); printf("size-inefficiency: %.2f ",100 * (size1 - size2) / size2); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

=+5 Does this case provide an example of the future for IHRM?

Answered: 1 week ago

Question

=+4 How did it affect HR?

Answered: 1 week ago