Computer Science, asked by savitabarodiya3, 5 months ago

discuss the memory requirements for classes, objects, data members,
111cmber functions, static and non static data members.​

Answers

Answered by ArunSivaPrakash
1

The memory requirements for classes, objects, data members, functions, and static and non-static data members in programming languages are given below.

Class

  • A class without an object requires no space allocated to it.
  • Memory is only allocated to the variables of the class when the object is created.
  • The size of the memory is equal to the sum of the sizes of the members defined in the class.
  • Class definitions are stored in a separate area called the method area.

Objects

  • The size of an object is equal to the sum of the sizes of the data members of the class, except static members.
  • The heap is used for storing objects in memory.

Data members

  • Memory for member functions is allocated per class and not per object.
  • The data members are stored in a contiguous allocation.

Functions

  • Whenever a function is called, its variables are allocated on the stack.
  • When the function call is over, the memory for the variables is de-allocated.

Static and non static data members

  • Memory for static data members is allocated per class.
  • Non-static variables in a class are allocated memory for each object declared of that class type.

#SPJ3

Similar questions