简体   繁体   中英

.NET Compact Framework, Properties performance issues and tracking of field change

I have a situation where I should track the FIRST changes applied to a field. This thing applies to "some" (10 if I'm not wrong) fields of a struct which I need to be as efficient as possible (it's a struct that will be intensively used to communicate information between threads for rendering/updating data; it's a message passing struct basically).

In this case I'm talking about xbox .net compact framework, I've heared that properties have performance issues because they are not inlined, so my question is:

What's the best way to face this situation?

2 Ideas:

1) I keep track of the first change done to a field, so I use a property that will automatically set a bit field to 1 to say "I've been changed!" (this bit field is part of a single int, so it's only a 4 byte overhead), but I'will waste all other calls to this property because they will simply change the value, because the bit is already set (until next frame obviusly)

2) I manually keep track of the change of the field (which will be public so), setting the bit with my own hands (more error possibilities but optimized)

Thanks for any suggestion

The only "improved" way of doing (1) that I can imagine would be using delegates - keep two versions of the property set code, one that sets the bit field and one that doesn't. Then make the property use the second version after the bit has been set. That way you will avoid the overhead of always setting the bit field (but will get a smaller overhead of making a delegate call).

As rsenna stated, the only solution I found is staying with public fields or work with functions without worring so much about slow execution. There isn't a solution for this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM