Example #1
0
        public void GenerateAllocations(List <CTFERecord> records)
        {
            Dictionary <string, int> types = new Dictionary <string, int>();

            foreach (CTFERecord record in records)
            {
                BAllocation allocation = null;
                string      type       = record.Er.GetValue("_TypeName").ToString();
                int         index;
                if (!types.TryGetValue(type, out index))
                {
                    types[type]     = index = types.Count;
                    allocation      = new BAllocation();
                    allocation.Type = type;
                    Allocations.Add(allocation);
                }
                else
                {
                    allocation = Allocations[index];
                }

                allocation.Count++;
                ulong size = Convert.ToUInt64(record.Er.GetValue("_AllocationAmount64"));
                if (size == 0)
                {
                    uint size32 = Convert.ToUInt32(record.Er.GetValue("_AllocationAmount"));
                    allocation.Size += size32;
                }
                else
                {
                    allocation.Size += size;
                }
            }
        }
        /// <summary>
        /// Allocates unmanaged memory.
        /// </summary>
        /// <param name="size">Number of bytes to allocate.</param>
        /// <param name="align">Allocation alignment in bytes.</param>
        /// <returns>Address of allocated memory.</returns>
        public static IntPtr Allocate(int size, int align)
        {
            // Lazily initialize container.
            if (Allocations == null)
            {
                Allocations = new List <AllocationItem>();
            }


            // Allocate unaligned memory block.
            var unalignedAddress = Marshal.AllocHGlobal(size + align);


            // Get aligned address.
            var shift = (unalignedAddress.ToInt64() & (align - 1));

            var alignedAddress = (shift != 0)
                ? new IntPtr(unalignedAddress.ToInt64() + align - shift)
                : unalignedAddress;


            // Register allocation.
            Allocations.Add(new AllocationItem
            {
                UnalignedAddress = unalignedAddress,
                AlignedAddress   = alignedAddress
            });


            // Return aligned address.
            return(alignedAddress);
        }
Example #3
0
        /// <summary>
        /// Try to reserve a memory block in the pool
        /// </summary>
        /// <param name="size">Size of the wanted block</param>
        /// <param name="address">Address of the memory allocation</param>
        /// <returns>True when a block could be reserved, false if not</returns>
        public bool Reserve(int size, out IntPtr address)
        {
            if (GetNextFreeBlock(size, out int offset))
            {
                Allocations.Add(offset, size);
                address = IntPtr.Add(Address, offset);
                return(true);
            }

            address = IntPtr.Zero;
            return(false);
        }
Example #4
0
 public bool AllocationsFromString(string allocString)
 {
     try
     {
         string[] allocations = allocString.Split(',');
         foreach (string s in allocations)
         {
             string[] accountAndValue = s.Split('/');
             Allocations.Add(new Allocation(accountAndValue[0], double.Parse(accountAndValue[1])));
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #5
0
        public static global::System.IntPtr Malloc(ulong size, [CallerMemberName] string memberName = "", [CallerFilePath] string fileName = "", [CallerLineNumber] int lineNumber = 0)
        {
            CallerInformation caller = new CallerInformation(memberName, fileName, lineNumber);
            IntPtr            __ret  = __Internal.JeMalloc(size);

            if (__ret != IntPtr.Zero)
            {
                Allocations.Add(__ret);
                //AllocationsDetails.Add(new Tuple<IntPtr, ulong, CallerInformation>(__ret, size, caller));

                return(__ret);
            }
            else
            {
                throw new OutOfMemoryException($"Could not allocate {size} bytes for {GetCallerDetails(caller)}.");
            }
        }
Example #6
0
        private void OnAddTrafficAllocationCommand()
        {
            var result = AddTrafficSplitWindow.PromptUser(_availableVersions);

            if (result != null)
            {
                var allocation = new SplitTrafficModel(
                    versionId: result.Version,
                    trafficAllocation: result.Allocation);

                // Remove the allocation from the list of available allocations to in future invocations the
                // user can only select the available ones.
                _availableVersions.Remove(allocation.VersionId);

                // Add the allocation to the list.
                Allocations.Add(allocation);

                // Update the visual state.
                UpdateCommands();
            }
        }
        public bool ValidateFile(string taffFilename, Validations validations)
        {
            if (taffFilename == null)
            {
                return(false);
            }

            int beforeNumOfError, afterNumOfError;

            beforeNumOfError = validations.ErrorValidationManager.Errors.Count;
            TaffFilename     = taffFilename;

            // Extract and validate the configuration data section
            GetCffFilename(taffFilename, validations);

            // Validate the rest of the taff file
            KeywordPair allocationPair = new KeywordPair(
                TaffKeywords.OPENING_ALLOCATION,
                TaffKeywords.CLOSING_ALLOCATION);
            PairSection openClosingAllocations = new PairSection(
                TaffKeywords.OPENING_ALLOCATIONS,
                TaffKeywords.CLOSING_ALLOCATIONS);
            StreamReader    streamReader    = new StreamReader(taffFilename);
            TaffAllocations taffAllocations = new TaffAllocations();
            int             lineNumber      = 1;
            string          line;

            validations.Filename = taffFilename;

            while (!streamReader.EndOfStream)
            {
                line = streamReader.ReadLine();
                line = line.Trim();
                validations.LineNumber = lineNumber.ToString();

                // Check if keyword is valid or not
                validations.CheckValidKeyword(line, TaffKeywords.KEYWORD_DICT);

                // Count Allocation Section
                allocationPair.CheckValidKeyword(line);

                // Check whether the line starts Opening/Closing Allocations section
                // If yes, mark it exist
                openClosingAllocations.MarkSection(line, lineNumber);

                // Validate and extract data in the Allocations section
                if (openClosingAllocations.ValidSectionPair[0] &&
                    !openClosingAllocations.ValidSectionPair[1])
                {
                    // Check whether Allocations section exists and
                    // whether line strt with the expected keyword, "COUNT", "TASKS"
                    // and "PROCESSORS"
                    Count              = taffAllocations.ExtractCount(Count, line, validations);
                    NumberOfTasks      = taffAllocations.ExtractNumOfTasks(NumberOfTasks, line, validations);
                    NumberOfProcessors = taffAllocations.ExtractNumOfProcessors(NumberOfProcessors, line, validations);

                    // Check whether the reader goes within the Allocation section
                    taffAllocations.MarkInsideAllocation(line, lineNumber, validations);

                    // Extract new allocation
                    Allocation newAllocation = taffAllocations.ExtractAllocation(line, NumberOfProcessors, NumberOfTasks, validations);

                    if (newAllocation != null)
                    {
                        Allocations.Add(newAllocation);
                    }
                }

                lineNumber++;
            }

            streamReader.Close();

            // Checking whether the Allocations section exists
            openClosingAllocations.CheckValidPair(validations, taffFilename);

            // Validate Allocation
            taffAllocations.ScanErrors(
                Count,
                NumberOfTasks,
                NumberOfProcessors,
                allocationPair,
                taffFilename,
                validations);

            AllocationInFileCount = allocationPair.CalculateNumOfPair();

            afterNumOfError = validations.ErrorValidationManager.Errors.Count;

            // Console.WriteLine($"{Count} | {NumberOfTasks} | {NumberOfProcessors}");
            // Console.WriteLine($"{Allocations.Count} | {allocationPair.CalculateNumOfPair()}");

            return(beforeNumOfError == afterNumOfError);
        }