Subject: Unix Internals Topic: Memory

Would you like us to handle your paper? Use our company for better grades and meet your deadlines.

Order a Similar Paper Order a Different Paper

Subject: Unix Internals       Topic: Memory

Requires knowledge of C Programming and UNIX Shell Scripting.       Deadline cannot be moved, unfortunately.

Part I is completed fully (see attached doc file). Parts II and III are built off Part I.

Subject: Unix Internals Topic: Memory
(Part I: Exploring the Memory Layout of a Struct) Program Listing: 1 /* 2 File: project.h 3 Course: CENG251 5 Date: Friday May 21, 2022 10:56 PM 6 */ 7 #define _project_h 8 #pragma once 9 10 #include 11 #include 12 13 //1. Create and declare your own data structure – mine is called project and its theme is based on rock climbing 14 struct PROJECT{ 15 char beta[15]; //Odd sized char string 16 int grade; 17 int year; 18 char type[10]; 19 float weight; 20 char sent; }; Program Listing: 1 /* 2 File: climbing.c 3 Course: CENG251 5 Date: Friday May 21, 2022 11:08 PM 6 */ 7 8 #include 9 #include 10 #include “project.h” 11 12 int main(int argc, char * argv[],char * envp[]) 13 { 14 struct PROJECT climb; 15 16 //2. Write a program that determines sizeof each of your fields and the whole data structure 17 fprintf(stdout,”The size of beta is %zun”, sizeof climb.beta); 18 fprintf(stdout,”The size of grade is %zun”, sizeof climb.grade); 19 fprintf(stdout,”The size of year is %zun”, sizeof climb.year); 20 fprintf(stdout,”The size of type is %zun”, sizeof climb.type); 21 fprintf(stdout,”The size of weight is %zun”, sizeof climb.weight); 22 fprintf(stdout,”The size of sent is %zun”, sizeof climb.sent); 23 fprintf(stdout,”The size of a climbing project is %zunn”, sizeof climb); 24 25 //3. Determine the offsets of each of the fields in your struct 26 fprintf(stdout,”The offset of beta is %zun”, offsetof(struct PROJECT,beta)); 27 fprintf(stdout,”The offset of grade is %zun”, offsetof(struct PROJECT,grade)); 28 fprintf(stdout,”The offset of year is %zun”, offsetof(struct PROJECT,year)); 29 fprintf(stdout,”The offset of type is %zun”, offsetof(struct PROJECT,type)); 30 fprintf(stdout,”The offset of weight is %zun”, offsetof(struct PROJECT,weight)); 31 fprintf(stdout,”The offset of sent is %zun”, offsetof(struct PROJECT,sent)); 32 33 return 0; 34 } Output: The sum of the parts is smaller than the size of the whole data structure. (Code for this section is included in program listing above – starting at line 34.) Output: The space saving occurred in fields beta and type, both of which are char type. Packing this program ensured that the alignment rule is ignored and therefore, the space was optimized by being compressed.

Once you get frustrated and struggling to accomplish your work on time, you need online assignment help. We understand your needs and provides you with reliable writing specialists to complete your projects at an affordable price.

Get a 15% discount on your order using the following coupon code SAVE15

Order a Similar Paper Order a Different Paper

Looking for this or a Similar Assignment? Click below to Place your Order



Click one of our contacts below to chat on WhatsApp

× How can I help you?