技术性很强的C#枚举问题... [英] Very Technical C# enum Question...

查看:68
本文介绍了技术性很强的C#枚举问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以1026(而不是0)开头的枚举集对性能有什么影响?这对程序集的执行速度或开关块布局有影响吗?

我最初的想法是,在一个常规实例(第一个val = 0)中,它可能会以某种方式用作内存块中的偏移量,但是开始枚举@ 1026会稍微影响此角度……更不用说在枚举值中使用空格他们的任务eFlag.val0 = 1026, eFlag.val1 = 5678, ...?

但是,由于枚举将始终是基本类型的大小,因此这也很有意义,因为它可以仅用作汇编代码中的标签形式,而且实际上没有关系...

..任何人都知道吗?

What is the performance impact of using an enum set which starts with a value say 1026 (as opposed to 0) and does this have any influence on execution speed or switch block layout in the assembly?

My initial thought is that in a customary instance (first val = 0) this may be used as an offset in the memory block somehow, however starting the enumeration @ 1026 affects this perspective a bit... let alone have enum values with spaces in their assignment eFlag.val0 = 1026, eFlag.val1 = 5678,...?

However it would also make sense that since the enum is always going to be the sizeof the base type, that this could be just used as a form of label in the assembled code, and it really doesn''t matter...

..anyone know?

推荐答案

每个枚举值默认都是原则上只是一个整数.因此,分配什么数字无关紧要.您可以设置基本类型,以减少对内存的影响.
Every enum value is per default principally just an integer. So it''s irrelevant what numbers you assign. You can btw set the base type which may reduce memory impact.
public enum Bla : byte
{
    A=123,
    B=255
}


我很确定,它不会对性能产生任何明显的影响.但听起来您最好为每种类型的大小声明只读字段或常量.
I''m pretty sure, it won''t have any noticable performance impact. But it sounds like you might be better off with declaring readonly fields or constants for each of the type sizes.


这篇关于技术性很强的C#枚举问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆