Memory Boxing Issues

private double _value;


public object Value
{
    get
   {
         return _value;
   }

}

Hi guys, just doing code reviews and spotting this in our codebase. This is not a typo, but my problems are related to the box that is involved in calling getter, and given that this code is in a type that is generated hundreds of times and the getter is called often, I see a memory problem.

Are my memory problems persisting? I mean, what are we doubling because of boxing?

+3
source share
4 answers

Yes, the code snippet you showed will really cause boxing. You force the runtime to convert doubleto object. If you want to prove it to yourself or a colleague, check the compiled IL for control commands boxand unbox.

, , , , , . , , , , , .

, , object . , , double.

. ( , , getter, , , .) Generics , , ( object).

+6

, , .

, .

? . , , . - , object double? object ( )?

- , , . , , , . , , API, .

+1

. Double , , . . , 16 32- 24 64-. . , , . , .

0

All Articles