ASSIGNMENT #6
Pengajar :
Tri Djoko Wahjono
Review
Question :
11. How does JavaScript support
sparse arrays?
=>Javascript objects are sparse, and
arrays are just specialized
objects with an auto-maintained
length property (which is
actually one larger than the largest index, not the number of
defined elements) and some additional methods.
12. What languages support
negative subscripts?
=> Ruby and Lua
support negative subscripts.
13. What languages support array
slices with stepsizes?
=>Ruby, Python, Perl.
14. What array initialization
feature is available in Ada that is not
available in other common imperative languages?
=>Ada provides two mechanisms for
initializing arrays in the
declarations statements : by listing them the order in which
they are to be stored, or by directly assigning them to an index
position using the => operator, which in Ada is called an arrow.
15. What is an aggregate constant?
=>A parenthesized lists of values.
Problem Set :
11. In the
Burroughs Extended ALGOL language, matrices are stored
as single-dimensioned
array of pointers to the rows of the matrix,
which are treated as single-dimensioned arrays of
values. What
are the advantages and disadvantages of such a scheme?
=>The advantage of
this scheme is that accesses that are done in
order of the rows can be
made very fast; once the pointer to a
row is gotten, all of the elements of the
row can
be fetched very
quickly. If, however, the elements of a matrix must be
accessed in column order, these
accesses will be much slower;
every access requires the fetch of a row pointer and an
address
computation from there. Note that this access technique was
devised to allow
multidimensional array rows to be segments in
a virtual storage management
technique. Using this method,
multidimensional arrays could be stored and
manipulated that
are much larger than the physical memory of the computer.
12. Analyze and
write a comparison of C’s malloc and free functions
with C++’s new and delete operators.
Use safety as the primary
consideration in the comparison.
=>New and Delete is a safe type. Malloc can return void value
to pointer access which is appropriate. New return pointer
type with itself. And for malloc, you must tell it how many bite
to allocate it. New will produce that value its self.
to pointer access which is appropriate. New return pointer
type with itself. And for malloc, you must tell it how many bite
to allocate it. New will produce that value its self.
13. Analyze and
write a comparison of using C++ pointers and Java
reference variables to refer to fixed heap-dynamic
variables. Use
safety and convenience as the primary considerations in the
comparison.
=> In c and C++ pointer can be use the
same way as addresses.
This design offer no solutions to the dangling
pointer or lost
heap-dynamic variable problems. Reference
types, such as
those in Java and C#, provide heap management without
the
dangers of pointers. so its clear that Java has more safety for
the heap-dynamic variables.
14. Write a
short discussion of what was lost and what was gained in
Java’s designers’ decision to not include the
pointers of C++.
=> With Java,
however, there’s a lot of those same programmers
felt that the security that
was gained was offset by the
decreases in speed and the fact that a lot of the earlier JIT
compilers were pretty
pokey didn't help that. For all their
faults, Sun's been pretty adamant about listening to
the
community so they've made a lot of improvements
regarding
in-place optimization, HotSpot, conditional compilation, etc.
15. What are the
arguments for and against Java’s implicit
heap storage recovery, when compared with the explicit
heap
storage recovery required in C++? Consider real-time
systems.
=>
Implicit eliminates the creation of dangling pointers. Disadv:
cpu-time to do recovery,
sometimes when there’s plenty of
heap storage so recovery isn’t necessary.
Tidak ada komentar:
Posting Komentar