When we create types, what will be the size of the memory?
For example:
Employee myAssistant = new Employee();
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 8, 2014, 5:22 AM EST
For user-defined types, there is no maximum memory size as such - though the allocation of such objects would of course be limited by available memory.
In practice, the biggest types are generally arrays, lists, dictionaries and strings. If a type requires more than 85K bytes it is stored in a special area of the heap (the large object heap or LOH).
In the normal heap, when objects are deleted, objects higher in memory are moved down to fill up the space and new objects are then allocated at the end.
In contrast, in the LOH, memory is not condensed in this way when objects are deleted. When new large objects are allocated an attempt is first made to allocate them in one of the 'holes' left by previously deleted objects and, if this proves impossible, then they are then allocated at the end of the LOH.
This can sometimes lead to a situation where an out of memory exception occurs even though there appears to be plenty of available memory remaining.
VulpesRank #55 · 29.2K reputationPosted Nov 8, 2014, 4:07 AM EST
1. The sum of the memory occupied by each of its fields.
2. Possibly some padding to ensure the fields are aligned on appropriate boundaries for the processor being used.
3, If Employee is a class, overhead of 8 bytes (32 bit processor) or 16 bytes (64 bit processor).
If Employee is a class, then the memory will be allocated on the heap and the variable, myAssistant, will contain a reference (a type of pointer) to this memory. This reference will occupy 4 bytes on a 32 bit processor or 8 bytes on a 64-bit processor.
If Employee is a struct, then the memory may be allocated on the stack or the heap (depending on the circumstances) and the variable myAssistant will contain the actual struct instance, not a reference to it.
MahaRank #2,573 · 543 reputationPosted Nov 8, 2014, 4:10 AM EST
MahaRank #2,573 · 543 reputationPosted Nov 8, 2014, 5:00 AM EST
MahaRank #2,573 · 543 reputationPosted Nov 8, 2014, 5:26 AM EST