Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programs written in a language that supports pointers and dynamic memory allocation can suffer from dangling pointers and lost heap-dynamic variables (or garbages). (a) A

image text in transcribed

Programs written in a language that supports pointers and dynamic memory allocation can suffer from dangling pointers and lost heap-dynamic variables (or garbages). (a) A dangling pointer is a pointer that contains the address of a piece of memory that no longer belongs to the program. Give one scenario that can cause dangling pointers. Support your scenario with sample codes in your favorite language. Poorly implemented languages leave the detection of the dangling pointer problem to the operating system. Suggest a language implementation method to allow run-time detection of dangling pointers by the language. (b) A lost heap-dynamic variable (or garbage) is an allocated heap-dynamic variable that is no longer accessible to the user program, although it still belongs to the program. Give a scenario that can cause lost heap-dynamic variables. Support your scenario with sample codes in your favorite language. The reference counter method is a way to detect garbages and reclaim the storage incrementally as soon as garbages are created. It works by maintaining in every cell a counter that stores the number of pointers that are currently pointing at the cell. Embedded in the decrement operation for the reference counters, which occurs when a pointer is disconnected from the cell, is a check for a zero value. If the reference counter reaches zero, it means that no program pointers are pointing at the cell, and the cell has thus become garbage and can be returned to the list of available space. Give three distinct disadvantages/problems with the reference counter method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions