answersLogoWhite

0

What is memory allocation of class?

User Avatar

Anonymous

12y ago
Updated: 8/20/2019

Classes are a declaration of a type and therefore do not allocate any memory apart from static members which exist throughout the life of the program (whether objects are instantiated from the class or not). Static member variables are allocated upon the stack, within the program's data segment, and should be listed in descending order of length to make best use of available memory (minimising padding resulting from alignment).

When an object is instantiated from a class, memory is allocated according to the sum total of all non-static member variable lengths, plus padding for alignment purposes. As with static member variables, non-static member variables should be listed in descending order of length to make the best use of available memory.

Classes that declare virtual methods (including pure-virtual methods) also set aside memory for the virtual table, the size of which is dependant upon the number of virtual methods.

Classes that allocate memory during construction or by assignment or class setters will require additional memory, however this memory is not included in the size of the class itself (only the member pointer lengths are included in the class size).

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What are types of memory allocation?

There are two types of memory allocations. 1. Static memory allocation 2. Dynamic memory allocation


What is meant by contiguous memory allocation in C?

Contiguous memory allocation in C programming refers to the assigning of consecutive memory blocks to a process. Contiguous memory allocation is one of the oldest and most popular memory allocation schemes in programming.


Compare and contrast dynamic memory allocation and the allocation of files in secondary storage?

Static Memory Allocation: Allocating the total memory requirements that a data structure might need all at once without regard for the actual amount needed at execution time. Dynamic Memory Allocation: The opposite strategy of static memory allocation - Dynamic Memory Allocation, involves allocating memory as-needed.


What Linked list uses.type of memory allocation?

Linked lists use dynamic memory allocation (also called "heap memory allocation", as the linked list is stored in heap memory).


What is contiguous memory allocation in os?

Memory allocation: When a program asks for memory and gets it. Contiguous allocation: When the memory is in one big block, for example memory addresses 1000-2000, as opposed to "fragmented allocation" where the memory comes as several smaller blocks in different places, for example memory addresses 1000-1050, 2050-2125, ...


How do you display matrix in c using dynamic memory allocation?

Memory allocation is not necessary to display a matrix.


Describe the major disadvantages for memory allocation schemes?

= for memory allocation schemes? = http://wiki.answers.com/Q/FAQ/2096= for memory allocation schemes? = http://wiki.answers.com/Q/FAQ/2096


Difference between contiguous and non contiguous memory allocation?

In a contiguous memory allocation there is no overhead during execution of a program. In a non contiguous memory allocation address translation is performed during execution.


At what time the memory is allocated for variable in c and c?

Static memory allocation occurs at compile time where as dynamic memory allocation occurs at run time.


Is there any difference in allocation of the memory of the member of class and object?

A class is the definition of a type -- it consumes no memory in an off itself. An object is an instance of a class, and therefore consumes memory, equal to the total size of all its member variables (attributes), including base class members, plus padding for alignment. If the class declares any virtual methods, a v-table is also created, which consumes additional memory.


How is partitioned allocation different from relocatable partitioned allocation?

Partitioned allocation is a fixed memory allocation technique which memory spaces are divided into smaller fixed partition, while Relocatable partitioning use variable and repartitioning technique


What do you mean by run time memory allocation?

When the allocation of memory to the program is done on need, during the execution of a program, it is called as the dynamic memory allocation. Memory is allocated from a free memory pool called as heap.The only way to access this dynamically allocated memory is through pointers. Dynamically allocated memory can be freed at run time and again added to heap.