using System;
using System.Collections.Generic;
///
/// 普通单例
///
///
public class Singleton where T : Singleton, new()
{
///
/// 单例
///
private static T m_Instance;
///
/// 实例
///
public static T Instance
{
get
{
if (object.ReferenceEquals(Singleton.m_Instance, null))
{
var obj = new T();
Singleton.m_Instance = obj;
Container.Add(typeof(T).Name, obj);
}
return Singleton.m_Instance;
}
}
///
/// 新能剖析方法,
///
/// 返回每个单例占用的内存大小
[Obsolete("没有意义,需要不断的遍历引用直到基础类型才能确定最终大小,-wg 2019年10月23日 11:42:21")]
public static Dictionary Profile_Size()
{
var dic = new Dictionary();
//foreach (var itc in Container) {
// // itc.Key
// System.Runtime.InteropServices.Marshal.SizeOf( itc.Value)
//}
return dic;
}
#region ' 内部容器 '
static Dictionary _mC;
static Dictionary Container
{
get
{
if (null == _mC)
{
_mC = new Dictionary();
}
return _mC;
}
}
#endregion
}