473,394 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why is form parent better than collection?

This article explains that parenting controls is better than adding them to
collections:
http://msdn.microsoft.com/smartclien...rmloadperf.asp.
However, it doesn't explain why. Please elaborate why parenting is better
than using collections.

Thanks,
Brett
Nov 17 '05 #1
2 1145
That is one strange article. Now, I haven't tried any of what the
author recommends, but my immediate reactions are as follows.

First your question: why is parenting better than adding to the control
collection? Note that the author didn't say "using collections": he's
talking about the relative speed of two ways of adding a control to a
container. You can say:

container.Controls.Add(control);

or

control.Parent = container;

Apparently (according to the author, at least), the latter is faster
than the former. Why? You'd have to look at the Framework code to know
for sure. My guess is that he just tried it and found that one was
faster than the other.

As for his assertion that instantiating a Rectangle and setting Bounds
is faster than setting Location and Size separately from a Point and a
Size respectively, the only thing I can think of is that the savings
must be within the Bounds property code itself, rather than
instantiation of one value type versus two. After all, the compiler
_ought_ to be able to figure out that new Point(10,20), new
Size(72,23), and new Rectangle(10,20,72,23) are all effectively
_constants_ and can be instantiated at compile time. (Note that I
haven't tried this... yet.) More likely the savings is in setting the
location and size all at once rather than in two steps.

Finally, notice the title of this article: we're talking Compact
Framework here, which means running on cell phones and smart
refrigerators. The kind of tweaks this guy is talking about will _not_
make any noticeable difference on a PC, and probably not even on a PDA.
We're talking very low-powered, low-resource devices before you'll see
any difference in your app from doing these kinds of optimizations.

If you do this for your regular-Framework, desktop PC app, all you'll
do is lose your ability to use the Visual Studio Designer, all for no
noticeable improvement in performace. In the end, it all comes back to
the cardinal rule of optimization: start by optimizing your design, not
your code. Optimize your code _only_ after you've used a profiler and
identified a bottleneck. Then you fix just the bottleneck. Anything
else is a massive waste of time, unless your boss is willing to pay for
your bragging rights.

Nov 17 '05 #2
Bruce Wood <br*******@canada.com> wrote:
Finally, notice the title of this article: we're talking Compact
Framework here, which means running on cell phones and smart
refrigerators. The kind of tweaks this guy is talking about will _not_
make any noticeable difference on a PC, and probably not even on a PDA.
We're talking very low-powered, low-resource devices before you'll see
any difference in your app from doing these kinds of optimizations.


I suspect it *would* make a difference on PDAs. It can be a real pain
getting the CF to initialize forms quickly enough - notice that the web
page claims a 49% speed increase through doing this, which would
certainly be noticeable on a PDA if your app is quite large.

I definitely agree that it wouldn't make a significant difference on
the desktop though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dfenestr8 | last post by:
Hi. I'm trying to build a page that has two frames, both of which are generated by a different cgi script. The lower frame is generated by a script called "control.py". The upper frame is...
0
by: TP-Software | last post by:
Hi, I have a ChatFormCollection class which holds a collection of the class ChatForm which inherits from Form. MainForm has an instance of ChatFormCollection. When a ChatForm instance is...
1
by: Yasutaka Ito | last post by:
Hi, I have an MDI application, in which I want to embed one form (System.Windows.Forms.Form) into a specified area of my MDI application. This is, wihtout affecting the capability of other child...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
16
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
4
by: SteveKlett | last post by:
I have a subset of form items that I need to perform different operations on (enable/disable, clear values, change style, etc) rather than hard code the IDs or names I would like to recursively...
6
NeoPa
by: NeoPa | last post by:
Introduction The first thing to understand about Sub-Forms is that, to add a form onto another form takes a special Subform control. This Subform control acts as a container for the form that you...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.