Java Reference
In-Depth Information
14. Recall that o
sets within a record or struct must sometimes be adjusted
upward due to alignment restrictions. Thus in the following two C
structs, S1 requires 6 bytes whereas S2 requires only 4 bytes.
ff
struct {
struct {
char
c1;
char
c1;
short s;
char
c2;
char
c2;
short s;
} S1;
} S2;
Assume we have a list of the fields in a record or struct. Each is charac-
terized by its size and alignment restriction. (A field with an alignment
restriction r must be assigned an o
set that is a multiple of r .)
Give an algorithm that determines an ordering of fields and minimizes
the overall size of a record or struct while maintaining all alignment re-
strictions. How does the execution time of your algorithm (as measured
in number of execution steps) grow as the number of fields increases?
ff
15. Assume we organize a heap using reference counts. What operations
must be done when a pointer to a heap object is assigned? What opera-
tions must be done when a scope is opened and closed?
16. Some languages, including C and C
, contain an operation that creates
apointertoadataobject. Thatis,p=&xtakes the address of object x,
whosetypeist, and assigns it to p,whosetypeist*.
How is management of the runtime stack complicated if it is possible to
create pointers to arbitrary data objects in frames? What restrictions on
the creation and copying of pointers to data objects su
++
ce to guarantee
the integrity of the runtime stack?
17. Consider a heap allocation strategy we shall term worst fit . Unlike best
fit, which allocates a heap request from the free space block that is closest
to the requested size, worst fit allocates a heap request from the largest
available free space block. What are the advantages and disadvantages
ofworstfitascomparedwiththebestfit,firstfit,andnextfitheap
allocation strategies?
Search WWH ::




Custom Search