//-------------------------------------------------------------------
		void PopulateDB( MemManager.Log.Log log )
		{
            DataSet myDataSet = new DataSet("DataSet");
			DataTable table;
			DataColumn column;
			DataGridColumnStyle columnstyle;
			string cats = "1Index|";
            if (mCategoryMode)
                cats += "0Category|";
            else
                cats += "0Heap|";

        //    cats+= "0Name|1Alignment|1ActualSize|1Count|1TotalSize";
            cats += "0Name|1ActualSize|1Count|1TotalSize";

			DataGridTableStyle tableStyle = new DataGridTableStyle(); 
			tableStyle.MappingName = "All"; 
			tableStyle.RowHeaderWidth = 10; 
			tableStyle.AlternatingBackColor = System.Drawing.Color.FromArgb(((System.Byte)(250)), ((System.Byte)(250)), ((System.Byte)(250)));

			table = new DataTable( "All" );
			table.BeginLoadData();
			foreach (string s in cats.Split('|'))
			{
				string n = s.Substring(1);

                //if (n == "Index")
                //    continue;
				column = new DataColumn();
				column.ColumnName = n;
				column.ReadOnly = true;
				column.Unique = false;				
				if (s[0] == '0')
				{
					column.DataType = System.Type.GetType("System.String");
					columnstyle = new DataGridTextBoxColumn();
				}
				else if (s[0] == '1')
				{
					column.DataType = System.Type.GetType("System.Int32");
					columnstyle = new DataGridTextBoxColumn();
				}
				else //if (s[0] == '2')
				{
					column.DataType = System.Type.GetType("System.Boolean");
					columnstyle = new DataGridBoolColumn();
				}
				table.Columns.Add(column);
				
				columnstyle.MappingName = n;
				columnstyle.HeaderText = n;
				columnstyle.Width = 70;
                if (n == "Name")
                    columnstyle.Width = 360;
                else if (n == "Heap")
                    columnstyle.Width = 70;
                else if (n == "Category")
                    columnstyle.Width = 90;
                else if (n == "Count" ) //|| n == "Alignment")
                    columnstyle.Width = 42;
				tableStyle.GridColumnStyles.Add( columnstyle );
			}

            for (int j = 0; j < mCollapsedView.Count; j++)
			{
                Item item = (Item)mCollapsedView[j];
                MemManager.Log.LogEntry le_a = log[item.index];

                string allocatorName = log.GetAllocator(le_a.allocator);
                string categoryName = mCategoryMode ? log.GetCategory(le_a.category) : log.GetCategory(0);

				DataRow row = table.NewRow();
				row["Index"] = item.index;
                if (mCategoryMode)
                    row["Category"] = categoryName;
                else
                    row["Heap"] = allocatorName;

             //   string removalString = log.GetAllocator(item.allocator) + "::";

             //   if (mCategoryMode)
              //      removalString += categoryName + "::";

                row["Name"] = log.GetString(le_a.nameString); //.Substring(removalString.Length);
           //     row["Alignment"] = item.alignment;
		//		row["ReqSize"] = item.requestedSize;
                row["ActualSize"] = le_a.allocSize;
				row["Count"] = item.count;
                row["TotalSize"] = item.count * le_a.allocSize;

                table.Rows.Add(row);
			}
			table.EndLoadData();

			// Add the table to the dataset
			myDataSet.Tables.Add(table);

			// Make the dataGrid use our new table style and bind it to our table 
			mDataGrid.TableStyles.Clear();
			mDataGrid.TableStyles.Add(tableStyle); 

			// Set up grid bindings
			mDataGrid.SetDataBinding(myDataSet, "All");

			// Update status
			UpdateStatusBar();
		}
        private void CreateMemoryGraph(MemManager.Log.Log log)
        {
            mRunningSumArray = new int[log.Count];
            int[] categoryrunningSum = null;
            if (mCategoryEnabled)
            {
                mNumberOfCategories = log.GetNumberCategories() - 1;  // ignore first category which is basically no category
                mCatSelectionBox.Items.Add("All");
                for (int i = 0; i < mNumberOfCategories; i++)
                    mCatSelectionBox.Items.Add(log.GetCategory((byte)(i + 1)));
                mCatSelectionBox.SelectedIndex = 0;

                mCategoryRunningSumArrays = new ArrayList[mNumberOfCategories];
                categoryrunningSum = new int[mNumberOfCategories];
                for (int i = 0; i < mNumberOfCategories; i++)
                {
                    mCategoryRunningSumArrays[i] = new ArrayList(log.Count);
                    categoryrunningSum[i] = 0;
                }
            }
            else
            {
                if (mNumberOfCategories > 0)
                {
                    for (int i = 0; i < mNumberOfCategories; i++)
                    {
                        mCategoryRunningSumArrays[i].Clear();
                        int gen = System.GC.GetGeneration(mCategoryRunningSumArrays[i]);
                        System.GC.Collect(gen);
                        mCategoryRunningSumArrays[i] = null;
                    }

                    mCategoryRunningSumArrays = null;
                }
                mNumberOfCategories = -1;
            }

            mUnflilteredRunningSumArrays = new int[log.Count];
            mLabelsArray = new ArrayList();
            mFramesArray = new ArrayList();

            mMaxMemoryAllocation = 0;
            mMinMemoryAllocation = 0;
            int runningSum = 0;
            int unfilteredRunningSum = 0;
            Regex regex = new Regex(mFilterTextBox.Text, RegexOptions.Compiled|RegexOptions.IgnoreCase);

            bool DoFiltering = (mFilterTextBox.Text != "");
            for (int i = 0; i < log.Count; i++)
            {
                MemManager.Log.LogEntry logentry = log[i];

                bool filtered = DoFiltering && !(regex.IsMatch(log.GetString(logentry.nameString)));

                if (!filtered)
                {
                    if (logentry.type == 'A')
                    {
                        runningSum += (int)logentry.allocSize;
                    }
                    else if (logentry.type == 'F')
                    {
                        runningSum -= (int)logentry.allocSize;
                    }
                }
                if (logentry.type == 'A')
                {
                    unfilteredRunningSum += (int)logentry.allocSize;
                    if (mCategoryEnabled)
                        categoryrunningSum[logentry.category - 1] += (int)logentry.allocSize;
                }
                else if (logentry.type == 'F')
                {
                    unfilteredRunningSum -= (int)logentry.allocSize;
                    if (mCategoryEnabled)
                        categoryrunningSum[logentry.category - 1] -= (int)logentry.allocSize;
                }
                else if (logentry.type == 'S')
                {
                    mFramesArray.Add(i);
                }
                else if (logentry.type == 'L')
                    mLabelsArray.Add(i);

                mRunningSumArray[i] = runningSum;
                mUnflilteredRunningSumArrays[i] = unfilteredRunningSum;
                for (int k = 0; k < mNumberOfCategories; k++)
                    mCategoryRunningSumArrays[k].Add(categoryrunningSum[k]);

                mMaxMemoryAllocation = Math.Max(mMaxMemoryAllocation, unfilteredRunningSum);
                mMinMemoryAllocation = Math.Min(unfilteredRunningSum, mMinMemoryAllocation);
            }
            mFramesArray.Add(log.Count);

            int maxMem = 1;
            while (maxMem < mMaxMemoryAllocation)
            {
                maxMem *= 2;
            }
            mMaxMemoryAllocation = maxMem;

            int minMem = 1;
            while (-minMem > mMinMemoryAllocation)
            {
                minMem *= 2;
            }
            mMinMemoryAllocation = minMem == 1 ? 0 : minMem;

            GenerateGraphicalData();
        }