开发者

C#. Where struct methods code kept in memory?

It is somewhat known where .NET keeps value types in memory (mostly in stack but could be in heap in certain circumstances etc)...

My question is - where is the code of the struct?

If I have say 16 byte of data fields in the struct and a massive computation method in it - I am presuming that 16 byte will be copied in stack and the开发者_StackOverflow中文版 method code is stored somewhere else and is shared for all instances of the struct.

Are these presumptions correct?


The MSIL is stored in the code section of the assembly - which Windows maps into memory when the assembly is first loaded. When the method is first executed the JIT will compile the MSIL to x86/x64 code. Once the method is compiled into memory it usually stays there and will be shared by all threads. There are some circumstances where multiple AppDomains will cause the MSIL to be compiled a second time, but it's rare.


Yes. Basically methods are managed separately in some structure that - basically - is not SO well known and documented (as noone ever needs it).

it is also kept as bytecode, compiled, may also be inlined in other methods.

The struct is known by type, so the calls to the methods can be routed properly.


This is a great article for figuring out what goes where.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜