private bool TryParseReadWriteIndexOrFail()
            {
                // If the read-write index doesn't exist. Just keep 'ReadWriteIndex' empty as it is.
                if (!File.Exists(m_Owner.ReadWriteIndexPath))
                {
                    return(true);
                }

                try
                {
                    using (var stream = File.OpenRead(m_Owner.ReadWriteIndexPath))
                    {
                        using (var br = new BinaryReader(stream))
                        {
                            ReadWriteIndex.FromBinary(br);
                        }
                    }
                }
                catch (Exception e)
                {
                    CoreLog.Warning($"Cannot parse the index file with exception '{e}'. Will try to clean up read-write path.");
                    ReadWriteIndex.Clear();
                    return(!File.Exists(m_Owner.ReadWriteIndexPath) || m_Owner.TryCleanUpReadWritePathOrFail(Fail));
                }

                return(true);
            }
Esempio n. 2
0
        /// <inheritdoc/>
        protected override TAssociate CreateAssociate <TKey, TAssociate>(out Type foundFor)
        {
            TAssociate associate = base.CreateAssociate <TKey, TAssociate>(out foundFor);

            if (associate != null)
            {
                return(associate);
            }
            // Ok, null, but probably just because type cast has failed;
            // let's try to wrap it. TKey is type for which we're getting
            // the comparer.
            IAdvancedComparerBase comparer = base.CreateAssociate <TKey, IAdvancedComparerBase>(out foundFor);

            if (foundFor == null)
            {
                CoreLog.Warning(Strings.LogCantFindAssociateFor,
                                TypeSuffixes.ToDelimitedString(" \\ "),
                                typeof(TAssociate).GetShortName(),
                                typeof(TKey).GetShortName());
                return(null);
            }
            if (foundFor == typeof(TKey))
            {
                return((TAssociate)comparer);
            }
            Type baseComparerWrapperType = typeof(BaseComparerWrapper <,>);

            associate =
                baseComparerWrapperType.Activate(new Type[] { typeof(TKey), foundFor }, ConstructorParams) as
                TAssociate;
            if (associate != null)
            {
                CoreLog.Warning(Strings.LogGenericAssociateIsUsedFor,
                                baseComparerWrapperType.GetShortName(),
                                typeof(TKey).GetShortName(),
                                foundFor.GetShortName(),
                                typeof(TKey).GetShortName());
                return(associate);
            }
            else
            {
                CoreLog.Warning(Strings.LogGenericAssociateCreationHasFailedFor,
                                baseComparerWrapperType.GetShortName(),
                                typeof(TKey).GetShortName(),
                                foundFor.GetShortName(),
                                typeof(TKey).GetShortName());
                return(null);
            }
        }
Esempio n. 3
0
        private static int GetDefaultStructLayoutPack()
        {
            int measureCount           = 128;
            int maxPack                = 128;
            int allocationToPackFactor = 4;

            TwoPointers[] objects       = new TwoPointers[16384];
            int[]         packCounts    = new int[maxPack];
            int           bestPack      = 0;
            int           bestPackCount = 0;

            for (int i = 0; i < measureCount; i++)
            {
//        for (int j = 0; j<objects.Length; j++)
//          objects[j] = null;
                long mem = GetFreeMemory();
                for (int j = 0; j < objects.Length; j++)
                {
                    objects[j] = new TwoPointers();
                }
                try {
                    long memDiff = GetFreeMemory() - mem;
                    int  pack    = (int)(memDiff / (allocationToPackFactor * objects.Length));
                    if (pack < 1 || pack > maxPack)
                    {
                        continue;
                    }
                    packCounts[pack]++;
                    if (bestPackCount < packCounts[pack])
                    {
                        bestPack      = pack;
                        bestPackCount = packCounts[pack];
                    }
                }
                catch (ArithmeticException) {
                }
            }
            if (bestPack < 1 || bestPack > maxPack)
            {
                CoreLog.Warning("Suspicious RuntimeInfo.DefaultStructLayoutPack value is detected: {0}", bestPack);
                bestPack = 4;
            }
            return(bestPack);
        }
Esempio n. 4
0
 public static void Warning(object message, Object context)
 {
     CoreLog.Warning(message, context);
 }
Esempio n. 5
0
 public static void Warning(object message)
 {
     CoreLog.Warning(message);
 }