Question

In: Computer Science

b) Now the opposite question: in general, when is it better to allocate an object dynamically...

b) Now the opposite question: in general, when is it better to allocate an object dynamically on the heap (as opposed to the statically on the stack)? Give an example of a programming scenario where an object should certainly be heap-allocated.

Solutions

Expert Solution

Generally, the objects are stored dynamically in Heap. That gives them the flexibilty of unlimited storage as opposed to the confined storage of an object stored in the stack statically. Not just the storage advantage, the objects stored in the Heap area are not automatically de-allocated and they are accesible at any point of time.We cannot have the knowledge that where in the heap area the particular object is placed Literally, it lives untill we explicitly de-allocate it. It lives untill the end of the function-call. In java these are cleared by Daemon Threads.So the life time of the object is also not fixed. The memory allocation is done at the run time.

If suppose a object in heap area is intialised with a value, the value of the onject remains unchanged through out the execution of code untill the program uses it. In such scenarios the heap allocations can be implemented.

Heap is used when the amount of memory needed by the object for allocation at the run time is unknown.

Let us consider a program that stores infomation of students. The list of students cannot be confined, because there are always entries and deletions. And the duration of the student that stays in the college is unkown. in such cases this can be employed.


Related Solutions

QUESTION 73 Gluconeogeneis is _________________. A. The exact opposite of glycolysis. B. More energetically favorable than...
QUESTION 73 Gluconeogeneis is _________________. A. The exact opposite of glycolysis. B. More energetically favorable than glycolysis. C. Energetically more costly than glycolysis. D. The amount of energy to perform gluconeogenesis is equal to the amount of energy in metabolizing glucose. QUESTION 72 Electrons extracted from fatty acids in the peroxisomes are transferred to __________________. A. NAD+ B. molecular oxygen C. cytochrome C D. Quinones QUESTION 65 What type of enzyme is required to catabolize an unsaturated fatty acid but...
Mark T or F in the left margin opposite the question number. When one entity (investor)...
Mark T or F in the left margin opposite the question number. When one entity (investor) acquires the shares of another entity (investee) and the investment results in significant influence: ___ 1. The investor may use the equity method to account for the investment if certain conditions are met and ASPE is followed. ___ 2. Under IFRS, the investment would generally require more extensive disclosures. ___ 3. The investor may use the cost method to account for the investment if...
Trade usually makes its participants better off. b) Identify an economist who agrees that in general...
Trade usually makes its participants better off. b) Identify an economist who agrees that in general free trade is a desirable way of organizing economic and social activity. Identify another economic concept that this Economist supports. Discuss how this economic concept can help you improve your life or society. Your answer needs to provide at least three paragraphs. The first paragraph provides information about the economist. The second paragraph identifies the economic concept that you have chosen. The third paragraph...
Linear Momentum of an object is conserved At all times    b. Only when the net external...
Linear Momentum of an object is conserved At all times    b. Only when the net external force on the object is Zero When the net external torque on the object is Zero    d. Never A truck of mass 4000 (kg) is moving at 10 (m/s). A car of mass 1000 (kg) is moving at 40 (m/s). So, the truck’s momentum, compared to the car, is Greater    b. Smaller    c. the same      d. Cannot say without knowing their accelerations A 1000...
The textbook basically says that the general addition rule is when A and B are two...
The textbook basically says that the general addition rule is when A and B are two events in a probability experiment. The probability that either one of the events will occur is: P (A or B) = P (A) + P (B) – P (A and B). For example, if you take out a single card from a pack of cards, what is the probability that the card is either an ace or spade? Therefore, P(A) = 4/52, P (B)...
Question 4. BONUS 20pts. Now relax and think about all studied topics in the General Physics...
Question 4. BONUS 20pts. Now relax and think about all studied topics in the General Physics course. You are asked to define 10 different " The right-hand rule". Here you first define the application and explain how the right-hand rule is applied to find the direction of physical concept. This is a free question that we expect independent study. DO NOT GET A COPY OF YOUR FRIENDS DEFINITION. OPEN THE BOOK AND FIND 10 DIFFERENT APPLICATION OF THE RULE. To...
a) When you establish a sinking fund, which interest rate is better? 7% or 8% b)...
a) When you establish a sinking fund, which interest rate is better? 7% or 8% b) If you set up a sinking fund, which interest rate is better? 4% compounded semi-annual or 4% compounded quarterly
(a) Consider the exercise in Question 1(b). The government now declares that steak burger meals in...
(a) Consider the exercise in Question 1(b). The government now declares that steak burger meals in that locality should sell for $5.00. Given the correct answers in Question 1(b), would this represent a price ceiling or a price floor? Explain. Further, determine what would be the quantity of shortage or surplus that would exist in this market, and be explicit whether it is a surplus or a shortage and explain why. (4 pts) (b) Given the readings you looked at...
Question 2 Consider the new trade model. Show how a country can be better o when...
Question 2 Consider the new trade model. Show how a country can be better o when it trades with an identical country. Explain your answer in detail using a diagram(s)..
Aquaplaning(General Question) What is happening physically when a pontoon of a floatplane begins to aquaplane. Like...
Aquaplaning(General Question) What is happening physically when a pontoon of a floatplane begins to aquaplane. Like are forces from water on the floats less because its not fully submerged anymore?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT