Question

class a
{
int variable;//4 bytes
}

class a
{
static int variable;//? bytes
}
Was it helpful?

Solution

The int variable also occupies 4 bytes, just not in the same place as the class and it occupies 4 bytes for each AppDomain, not for each instance of the class.

OTHER TIPS

The same number of bytes.

4 bytes for every appdomain it is loaded into. NOT counting the overhad of the carrying class, which is assume to be thereanyway (i.e. you will not have JUST the static variable in it).

It depends on the hardware, as an int is not always 4 bytes. On x86 the static int takes the same number of bytes as as a non-static one.

You should probably use sizeof() or something like that if you are trying to allocate memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top