0
class a
{
int variable;//4 bytes
}

class a
{
static int variable;//? bytes
}

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

The same number of bytes.

Comments

1

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).

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.