after p new fredn how does the compiler know


After p = new Fred[n], how does the compiler know about n objects to be destructed throughout delete[] p?

A:  The run-time system hold the number of objects, n, somewhere where it may be retrieved if you know the pointer, p only. There are two famous techniques that do this. Both of these technique are in use trhough commercial-grade compilers, both have tradeoffs, & neither is perfect. These techniques are following:

Over-allocate the array & put n only to the left of the first Fred object. Employ an associative array along with p as the key and n as the value.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: after p new fredn how does the compiler know
Reference No:- TGS0217529

Expected delivery within 24 Hours