《再探c 类与结构体究竟谁快——考虑栈变量、栈分配、位整数、密封类》由会员分享,可在线阅读,更多相关《再探c 类与结构体究竟谁快——考虑栈变量、栈分配、位整数、密封类(19页珍藏版)》请在金锄头文库上搜索。
1、再探C#类与结构体究竟谁快考虑栈变量、栈分配、64位整数、密封类 上次我对C#类与结构体做了一次速度评测(http:/ System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace TryPointerCall / / 指针操作接口 / public interface IPointerCall / / 指针操作 / / 源指针 / 修改后指针 unsafe byte* Ptr(byte* p); #region 非泛型 / / 非泛型 指针操作基类 / publ
2、ic abstract class PointerCall : IPointerCall public abstract unsafe byte* Ptr(byte* p); / / 非泛型 指针操作派生类: 指针+偏移 / public sealed class PointerCallAdd : PointerCall / / 偏移值 / public int Offset = 0; public override unsafe byte* Ptr(byte* p) return unchecked(p + Offset); / / 非泛型 指针操作密封类: 指针+偏移 / public s
3、ealed class SldPointerCallAdd : IPointerCall / / 偏移值 / public int Offset = 0; public unsafe byte* Ptr(byte* p) return unchecked(p + Offset); / / 非泛型 指针操作结构体: 指针+偏移 / public struct SPointerCallAdd : IPointerCall / / 偏移值 / public int Offset; public unsafe byte* Ptr(byte* p) return unchecked(p + Offset); #endregion #region 泛型 / ! C#不支持将整数类型作为泛型约束 ! /public abstract cla