コード例 #1
0
        /// <summary>
        /// Attempts to get shared pool for specified key serializer from inner storage
        /// </summary>
        /// <param name="keySerializer">Key serializer</param>
        /// <param name="pool">Extracted pool on success</param>
        /// <returns>True if pool for specific serializer is found</returns>
        public static bool TryGetSharedPool(IBobKeySerializer keySerializer, out ByteArrayPool pool)
        {
            if (keySerializer == null)
            {
                throw new ArgumentNullException(nameof(keySerializer));
            }

            lock (_syncObject)
            {
                return(_sharedPools.TryGetValue(new DictionaryKey(keySerializer), out pool));
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets or creates shared pool for specified key serializer
        /// </summary>
        /// <param name="keySerializer">Key serializer</param>
        /// <returns>Create pool</returns>
        public static ByteArrayPool GetOrCreateSharedPool(IBobKeySerializer keySerializer)
        {
            if (keySerializer == null)
            {
                throw new ArgumentNullException(nameof(keySerializer));
            }

            lock (_syncObject)
            {
                ByteArrayPool result = null;
                if (_sharedPools.TryGetValue(new DictionaryKey(keySerializer), out result))
                {
                    return(result);
                }

                result = CreateSharedPool(keySerializer);
                _sharedPools[new DictionaryKey(keySerializer)] = result;
                return(result);
            }
        }