G. Ghez
G. Ghez

Reputation: 3603

ldloc var vs. ldloc.n

Do someone know if there is even a small difference using ldloc var CIL instruction and ldloc.n ?

Considering this local var table in a method scope :

.locals init ([0] int32 a,
              [1] int32 b)

Are those instructions:

ldloc.0
ldloc.1

better, worste or equal than:

ldloc a
ldloc b

Upvotes: 2

Views: 442

Answers (1)

IS4
IS4

Reputation: 13207

There are many shortened forms of common opcodes with a simple goal - to shorten the length of the method. ldloc.n instructions take up one byte, ldloc.s n two bytes, and ldloc n three bytes. This is useful for inlining, as methods longer than 16 bytes are not eligible for it.

Upvotes: 2

Related Questions