Subject: Unix Internals Topic: Memory

Get perfect grades by consistently using www.assignmentgeeks.org. Place your order and get a quality paper today. Take advantage of our current 20% discount by using the coupon code GET20


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.

Writerbay.net

Do you need help with this or a different assignment? We offer CONFIDENTIAL, ORIGINAL (Turnitin/LopesWrite/SafeAssign checks), and PRIVATE services using latest (within 5 years) peer-reviewed articles. Kindly click on ORDER NOW to receive an A++ paper from our masters- and PhD writers.

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


Order a Similar Paper Order a Different Paper