Beispiel #1
0
 public BinTree(int ThreadId, TreeType treeType)
 {
     // the following intended to ensure the console output was legible...
     //Console.SetOut(TextWriter.Synchronized(Console.Out));
     m_TreeType = treeType;
     m_pRoot = null;
     m_Random = new Random();
 }
Beispiel #2
0
 // Build tree top down, assigning to older objects.
 internal static void Populate(int iDepth, Node thisNode)
 {
     if (iDepth<=0)
     {
         return;
     }
     else
     {
         iDepth--;
         thisNode.left  = new Node();
         thisNode.right = new Node();
         Populate (iDepth, thisNode.left);
         Populate (iDepth, thisNode.right);
     }
 }
Beispiel #3
0
        public bool runTest(int iRep, int iObj)
        {
            m_Root = new Node();
            m_Root.m_Var = null;
            m_Root.next = null;
            Node temp = m_Root;
            for(int i = 0; i < iRep; i++)
            {
                temp.next = new Node();
                temp = temp.next;
                temp.m_Var = (i);
                temp.next = null;
                if ((i+1)%10000 == 0)
                {
                    Console.Write("Nodes Created: ");
                    Console.WriteLine(i+1);
                }
            }
            temp = m_Root;
            m_Root = null;

            Console.WriteLine("Done creating");

            for(int i = 0; i < iRep; i++)
            {
                temp = temp.next;
                if ((i+1)%10000 == 0)
                {
                    Console.Write("Nodes Traversed: ");
                    Console.WriteLine(i + 1);
                    GC.Collect();
                }
            }
            GC.Collect();
            return true;
        }
Beispiel #4
0
        public void SpinWheel( Dictionary<int, WeakReference> oTable,  Node node, Random r )
        {
            int iKey;//the index which the new node will be set at
            Node nValue;//the new node
            bool bDel;

            //Console.WriteLine( "start spinwheel ");

            iKey = r.Next( 0, LeakWheel.iTable );

            if( iKey%2 == 0 ) //decide whether delete or create a node.
                bDel = true; //delete
            else
                bDel = false;

            if( !bDel )
            {
                nValue = CreateNode( iKey );

                if( oTable.ContainsKey(iKey) && (oTable[iKey]).IsAlive )
                {
                    SetChildNode(oTable, iKey, nValue );
                }
                else
                {
                    LstNode = SetNodeInTable(iKey, nValue, node, oTable);
                }
            }
            else
            {
                DeleteNode( iKey, oTable);
            }
            //if (iKey % 100 == 0)
            //{
            //    Console.WriteLine("HeapSize: {0}", GC.GetTotalMemory(false));
            //}
        }
Beispiel #5
0
 public void DestroyLstNode() {
     LstNode = null;
 }
Beispiel #6
0
 public void DeleteNodes (int howMany, int ThreadId)
 {
     for (int i = 0; i < howMany; i++)
     {
         m_pRoot = Delete(m_pRoot, m_Random.Next(100) );
     }
     Console.Out.WriteLine("Thread " + ThreadId +" Deleted: " + howMany + " Nodes: " + GC.GetTotalMemory(false));
 }
Beispiel #7
0
 public void Empty (int ThreadId)
 {
     Console.Out.WriteLine("Thread " + ThreadId + ": Tree Empty");
     m_pRoot = null;
 }
Beispiel #8
0
        public void ThreadNode()
        {
            Dictionary<int, WeakReference> oTable = new Dictionary<int, WeakReference>( 10);
            Node LstNode = null; //the last node in the node chain//
            Random  r = new Random (LeakWheel.iSeed);
            LeakWheel mv_obj = new LeakWheel();

            while (true)
            {
                LstNode = mv_obj.SpinWheel( oTable, LstNode, r );

                if( GC.GetTotalMemory(false) >= LeakWheel.iMem*60 )
                {
                    LstNode = null;

                    GC.Collect( );
                    GC.WaitForPendingFinalizers();
                    GC.Collect( );
                    Console.WriteLine( "After Delete and GCed all Objects: {0}", GC.GetTotalMemory(false) );
                }
            }
        }
Beispiel #9
0
 public Node CreateNode( int iKey )
 {
     Node newNode = new Node( );
     switch( iKey%5 )
     {
     //case 0://1 out of 4 nodes are thread node.
     //    newNode.SetThread( );
     //break;
     case 1://This node include a binary tree
         newNode.SettreeNode( iKey );
     break;
     case 2: //This node with a Variant array.
         newNode.SetVararyNode( iKey );
     break;
     case 3: //This node with a BitArray
         newNode.SetBitArrayNode( iKey );
     break;
     case 0:
     case 4: //small node
         newNode.SetSmallNode( iKey );
     break;
     }
     return newNode;
 }
Beispiel #10
0
        public Node Insert(Node root, int element)
        {
            if(root == null)                                            //if is NULL make a new node
            {                                                           //and copy number to the new node
                root=new Node();                                        //make new node
                root.m_data = element;                                  //copy number
                root.m_pLeft=null ;                                     //set the children to NULL
                root.m_pRight=null;
            }
            else if(element < root.m_data)
            {
                root.m_pLeft = Insert(root.m_pLeft, element);
            }
            else
            {
                root.m_pRight = Insert(root.m_pRight, element);
            }

            if (m_TreeType==TreeType.Growing)
            {
                root.Grow();
            }
            else if (m_TreeType==TreeType.Living)
            {
                root.Live();
            }

            return root;
        }
Beispiel #11
0
 internal Node(Node l, Node r)
 {
     left = l;
     right = r;
 }
Beispiel #12
0
        public static int Main(String [] args)
        {
            Node    longLivedTree;
            Node    tempTree;

            Console.WriteLine("Test should return with ExitCode 100 ...");

            GCBench Mv_Obj = new GCBench();

            // Stretch the memory space quickly
            tempTree = MakeTree(kStretchTreeDepth);
            tempTree = null;

            // Create a long lived object
            longLivedTree = new Node();
            Populate(kLongLivedTreeDepth, longLivedTree);

            // Create long-lived array, filling half of it
            double []array = new double[kArraySize];
            for (int i = 0; i < kArraySize/2; ++i)
            {
                array[i] = 1.0/i;
            }

            GC.Collect();

            for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2)
            {
                Mv_Obj.TimeConstruction(d);
            }

            Console.WriteLine("Test Passed");
            return 100;
        }
Beispiel #13
0
        internal void TimeConstruction(int depth)
        {

            int     iNumIters = NumIters(depth);
            Node    tempTree;

            for (int i = 0; i < iNumIters; ++i)
            {
                tempTree = new Node();
                Populate(depth, tempTree);
                tempTree = null;
            }


            for (int i = 0; i < iNumIters; ++i)
            {
                tempTree = MakeTree(depth);
                tempTree = null;
            }

        }
Beispiel #14
0
 public Node SetNodeInTable(int iKey, Node nValue, Node LstNode, Dictionary<int, WeakReference> oTable )
 {
     /**************************************************/
     /* save new node in a chain, all the node is      */
     /* refereced by this chain, Table only have their */
     /* Weakreferece. So when delete a node, only need */
     /* to delete the ref in this chain.               */
     /**************************************************/
     if( LstNode == null )
         LstNode = nValue;
     else
     {
         LstNode.Next = nValue ;
         LstNode.Next.Last = LstNode;
         LstNode = LstNode.Next;
     }
     WeakReference wRef = new WeakReference( LstNode, false );
     if( oTable.ContainsKey(iKey) )
     {
         oTable[iKey] = wRef;
     }
     else
     {
         oTable.Add( iKey, wRef );
     }
     return LstNode; //keep the last node fresh in chain
 }
Beispiel #15
0
        public Node Delete(Node root, int element)
        {
            Node temp = null;

            if (root == null)
            {
                return null;                                                //Node not found
            }
            else if (element == root.m_data)                                 //if it was the first data (node)
            {
                if(root.m_pRight == null)                                       //check if it has right child.
                {                                                           //If it has no right child
                    return root.m_pLeft;
                }

                if (root.m_pLeft == null)
                {
                    return root.m_pRight;
                }
                else
                {
                    for (temp = root.m_pLeft; temp.m_pRight != null; temp = temp.m_pRight);
                    root.m_data = temp.m_data;
                    root.m_pLeft = Delete(root.m_pLeft, temp.m_data);
                }
            }
            else if (root.m_data > element)
            {
                root.m_pLeft = Delete(root.m_pLeft, element);
            }
            else
            {
                root.m_pRight = Delete(root.m_pRight, element);
            }

            if (m_TreeType==TreeType.Growing)
            {
                root.Grow();
            }
            else if (m_TreeType==TreeType.Living)
            {
                root.Live();
            }

            return root;
        }
Beispiel #16
0
        public void SetChildNode( Dictionary<int, WeakReference> oTable, int iKey, Node nValue )
        {
            WeakReference wRef= oTable[iKey];
            WeakReference wRefChild = wRef;
            Node thisNode = (Node)wRefChild.Target;
            Node ChildNode = thisNode;

            while( ChildNode.Child != null )
            {
                ChildNode = ChildNode.Child;
            }
            ChildNode.Child = nValue;
            ChildNode.Child.Parent = ChildNode;
        }
Beispiel #17
0
 public BinTree(int ThreadId, TreeType treeType)
 {
     m_TreeType = treeType;
     m_pRoot = null;
     m_Random = new Random();
 }
Beispiel #18
0
        internal int itype; //0=VarAry;1=BitAry;2=small;3=binarytree;4=Thread

        public Node()
        {
            Last = null;
            Next = null;
            Parent = null;
            Child = null;
            ThrdNode = null;
            itype = -1;
        }
Beispiel #19
0
        public bool RunGame()
        {
            Dictionary<int, WeakReference> oTable = new Dictionary<int, WeakReference>(10);
            LstNode = null; //the last node in the node chain//
            Random  r = new Random (LeakWheel.iSeed);

            for(int i=0; i<iIter; i++)
            {
                LstNode = SpinWheel(oTable, LstNode, r);
               
                if( GC.GetTotalMemory(false)/(1024*1024) >= iMem )
                {
                    LstNode = null;

                    GC.Collect( );
                    GC.WaitForPendingFinalizers();
                    GC.Collect( );

                    Console.WriteLine( "After Delete and GCed all Objects: {0}", GC.GetTotalMemory(false) );
                }
            }

            LstNode = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Thread.Sleep(100);
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();


            Console.WriteLine("When test finished: {0}", GC.GetTotalMemory(false));
            Console.WriteLine("Created VarAry objects: {0} Finalized VarAry Objects: {1}", Node.iVarAryCreat, Node.iVarAryFinal);
            Console.WriteLine("Created BitArray objects: {0} Finalized BitArray Objects: {1}", Node.iBitAryCreat, Node.iBitAryFinal);
            Console.WriteLine("Created small objects: {0} Finalized small Objects: {1}", Node.iSmallCreat, Node.iSmallFinal);
            Console.WriteLine("Created BinaryTree objects: {0} Finalized BinaryTree Objects: {1}", Node.iBiTreeCreat, Node.iBiTreeFinal);
            Console.WriteLine("Created Thread objects: {0} Finalized Thread Objects: {1}", Node.iThrdCreat, Node.iThrdFinal);


            return (Node.iBitAryCreat == Node.iBitAryFinal &&
                    Node.iBiTreeCreat == Node.iBiTreeFinal &&
                    Node.iSmallCreat == Node.iSmallFinal &&
                    Node.iThrdCreat == Node.iThrdFinal &&
                    Node.iVarAryCreat == Node.iVarAryFinal);
        }