The fastest way to destroy a tree structure in VB6

I have code in VB6 that creates a moderately large tree structure (several thousand nodes). Performance is adequate if you do not destroy the last link to the tree. Sometimes it may take a few seconds. I tried to kill all the internal links in each node before deleting the node itself, but this does not seem to help. Is there any trick to speed up vb6 with my link counts? It seems that performance has a significant aspect of N ^ 2.

By the way, I know that VB6 is becoming obsolete, but I have someone complaining about this code that I wrote a long time ago, but which is still in use.

BTW, the tree is not a binary tree, but instead allows each node to have an arbitrary number of children stored in the collection and accessible by name (so that one node can be TheTree! This! That! TheOtherThing! Whatever it is, otherwise TheTree (" This ") (" This ") (" TheOtherThing ") (" Whatever happens ")).

+7
source share
3 answers

The objects in the VB6 collection are notorious for slowly releasing their contents, for example when there are many links contained.

You can try replacing the collection like this . There are a number of other replacement collections for VB6 that should drop significantly in compatibility.

You can also read on Bruce Mckinney to take on the collection object.

EDIT: More information from Bruce McKinney here

+3
source

I hate being the bearer of bad news, but I doubt that you can reduce the time it takes to complete the tree of objects. 10 years ago or so, I co-developed SQL Accord in VB6, an application that compares databases. Thus, you can imagine that you keep thousands of objects in memory (for example, tables / view / sproc / etc definitions) to be able to quickly compare them.

The initial design for storing these items in collections fell to the floor due to problems raised by the OP. The culprit is the garbage collection COM - it should clear the moment when you set the object to Nothing / Null, and then, most likely, it needs to defragment the memory space - this takes time.

My solution (painful at that time) was to convert all objects to TYPE structures and convert collections to type arrays. Then I created manager objects to work with arrays / types, etc ...

Despite the fact that the code smells when you look at it, I got a 10-fold increase in performance. What for? Since TYPE structures go on the stack, and objects go on the heap, where it is much cheaper to manage them.

+1
source

Curland Advanced Visual Basic explains how to create lightweight COM objects and how to organize their instances in large object systems that use a user memory manager. The advantage is that you can allocate a large unit (or several, but not a lot) of memory for storage all copies that can be released at a time. This reduces the stall time to zero.

Lightweight objects are structures ( Type in VB6) wrapped in COM interfaces to look like regular COM objects. UDT arrays are allocated and destroyed very quickly, since they occupy one piece of memory.

0
source

All Articles