After p = new fred[n], how does the compiler know about , C/C++ Programming

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.

 

Posted Date: 3/19/2013 8:49:21 AM | Location : United States







Related Discussions:- After p = new fred[n], how does the compiler know about , Assignment Help, Ask Question on After p = new fred[n], how does the compiler know about , Get Answer, Expert's Help, After p = new fred[n], how does the compiler know about Discussions

Write discussion on After p = new fred[n], how does the compiler know about
Your posts are moderated
Related Questions
there is a pebble merchant. he sells the pebbles,that are used for shining the floor.his main duty is to take the length of the room side but he sometines mistakes doing that and m

In this lab, please complete a given program to perform the following tasks: 1. Allocate a 10 by 5 2D byte array dynamically. The way of allocation must be consistent with page

Define the Meaning of Call by reference? In "call-by- reference", as an alternative of passing the value of a variable, the location number (or the address) of the variable is

write a grading program for a class with the following grading polices: a.there are two quizzes eaxh graded on the basis of 10 points b.there is ome midterm exam and one final exam

C Program to check PRIME NUMBERS   main() {           int i,k,r,flag;           clrscr();           printf("ENTER THE NO. TO CHECK IT IS PRIME OR NOT: ");

Draw pie chart in c++ program: int main() {                 char cmd;                   cout                 cout                 cmd = toupper(getch());

Task Your task is to write a program, words, that reports information about the number of words read from its standard input. For example, if the file qbf.txtcontains the text th

exemples of many to many

A: No. If they're utilized properly, they increase encapsulation. You frequently require splitting a class in half while the two halves will have distinct numbers of instances o

#write a program that counts the number of occurances of the string in the n-th padovan string p(n)