/// <summary> /// Initialize the keys for different key types. /// </summary> public int InitKeys(UInt32 typeId, int numKeys, int maxSize) { Util.Log("InitKeys typeId " + typeId + " numKeys= " + numKeys + "maxSize=" + maxSize); Assert.Greater(numKeys, 0, "Number of keys should be greater than zero."); Type type = CacheableWrapperFactory.GetTypeForId(typeId); CacheableKeyWrapper instance = CacheableWrapperFactory.CreateKeyInstance(typeId); Assert.IsNotNull(instance, "InitKeys: Type '{0}' could not be instantiated.", type.Name); int maxKeys = instance.MaxKeys; if (numKeys > maxKeys) { numKeys = maxKeys; } m_cKeys = new CacheableKeyWrapper[numKeys]; m_cKeyCksums = new uint[numKeys]; for (int keyIndex = 0; keyIndex < numKeys; keyIndex++) { instance = CacheableWrapperFactory.CreateKeyInstance(typeId); instance.InitKey(keyIndex, maxSize); m_cKeyCksums[keyIndex] = instance.GetChecksum(); m_cKeys[keyIndex] = instance; } Util.Log("InitKeys final m_cKeyCksums " + m_cKeyCksums.Length + " m_cKeys:" + m_cKeys.Length + "numKeys: " + numKeys); return(numKeys); }
public static CacheableKeyWrapper CreateKeyInstance(UInt32 typeId) { CacheableKeyWrapperDelegate wrapperDelegate; lock (((ICollection)m_registeredKeyTypeIdMap).SyncRoot) { if (m_registeredKeyTypeIdMap.TryGetValue(typeId, out wrapperDelegate)) { CacheableKeyWrapper wrapper = wrapperDelegate(); wrapper.TypeId = typeId; return(wrapper); } } return(null); }