0 Replies - 875 Views - Last Post: 25 November 2010 - 11:29 PM

#1 RLB31384   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 97
  • Joined: 29-January 10

Array of Records memory useage

Posted 25 November 2010 - 11:29 PM

Suppose we are compiling for a machine with 1-byte characters, 2 bye shorts, 4 bye ints, and 8 byte reals, and with alignment rules that require the address of every primitive data element to be an even multiple of element's size. Suppose further that the compiler is not permitted to reorder fields. How much space will be consumed by the following array?

array [0.9] of record
s : short
c: char
t : short
d : char
r : real
i : integer

okay my book says that there would be holes in a struct, the largest is 8 bytes..so all the data elements would be 8 bytes but would have holes. 8 x 6 = 48 byes.

However my book also says most compilers would devote 20 bytes to every member of an array...48 is larger so would it just be 48 x 10 = 480 bytes?

For memory layout of arrays it says that for arrays of records, it is common for each subsequent element to be aligned at an address appropriate for any type; small holes between consecutive records may result.
Is this talking about the same holes I already mentioned or is there also holes between the elements of the array?

Thanks

Is This A Good Question/Topic? 0
  • +

Page 1 of 1