In: Computer Science
2. Describe one advantage and one disadvantage for each of the following design decisions:
a. having a garbage collector
b. type coercion
c. dynamic length strings
A]Garbage Collector
garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.
here are some advantage and disadvantage for having garbage collector.
Advantage:
1)The allocation of free objects is simple and fast.
2)This method does not cause memory fragmentation, even when objects of different sizes are copied.
Disadvantage:
1)Although garbage collector runs in its own thread, still it has impact on performance.
2)Garbage collector can be force to run using "System.gc" or "Runtime.gc".
B] Type Coercion
is the process of converting value from one type to another such as string to number, object to boolean, and so on. Any type, be it primitive or an object, is a valid subject for type coercion.
Advantage:
1) It basically free the programmer from the low level concerns upto some level. as Adding two different data types Real & int
Disadvantage:
1)some level is reduced which may be that it hides some serious errors which will not be easy to point out.
C]Dynamic length strings:
Allows strings various length with no maximum. Requires the overhead of dynamic storage allocation and deallocation but provides flexibility.
Advantage:
1)Strings can be stored in a linked list Complexity of string operations, pointer chasing
Disadvantage:
1)Need run-time descriptor b/c only current length needs to be stored.