However, the program become more and more complex, and now, in the load event of any form, i have hundreds of statements, which makes them take more than 10 seconds to display. I want to overstep this difficulty and i found out that vb.net can sometimes be pretty slow, because it is "managed" code (?). Some people suggested me i should stick with native c++, which should build programs that execute much faster, are more robust and offer a greater control over the programming. I also always wanted to learn c++, so this sounds appealing to me
20 Replies - 338 Views - Last Post: 15 January 2013 - 11:54 AM
#1
vb.net vs. vc++?
Posted 15 January 2013 - 05:47 AM
However, the program become more and more complex, and now, in the load event of any form, i have hundreds of statements, which makes them take more than 10 seconds to display. I want to overstep this difficulty and i found out that vb.net can sometimes be pretty slow, because it is "managed" code (?). Some people suggested me i should stick with native c++, which should build programs that execute much faster, are more robust and offer a greater control over the programming. I also always wanted to learn c++, so this sounds appealing to me
Replies To: vb.net vs. vc++?
#2
Re: vb.net vs. vc++?
Posted 15 January 2013 - 06:46 AM
How about you switch to WPF instead of C++. Learning curve is smaller and that will guarantee that your controls will be fast because all you are doing above can be done pretty simply with XAML.
For example, here is the Record button (I assumed it was a button) in your code quickly written in XAML:
<Button BorderThickness="0">
<StackPanel Orientation="Horizontal" Height="40">
<Border Background="Purple" Width="20" />
<TextBlock Text="1" FontSize="50" Margin="0,-15,0,0" Foreground="Red" />
<Border CornerRadius="0,20,20,0" Width="100" Background="Blue" >
<TextBlock Text="RECORD" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</StackPanel>
</Button>
No need to write any actual VB code for styling the UI. You can also search for sample UIs done with WPF by using google's image search (search for "WPF ui design" for example)
So I would suggest to create a small sample application with WPF so you know if it's fast enough (should be) and fills your needs. If it doesn't, I doubt that just C++ will either. Writing applications in C++ won't make them fast automatically. Sure, it might give you 10% boost in performance but slow code is still slow.
Btw. Have you tried to figure out why your code runs so slow? Try to set up some StopWatches inside your startup code to see which sections are bottlenecks.
#3
Re: vb.net vs. vc++?
Posted 15 January 2013 - 07:05 AM
So, first of all, that style of interface, buttons, etc is called LCARS and is the style of GUI used on the fictional computer displays and consoles in the TV series "Star Trek". What we started to do was to make a Windows Explorer-like shell, but with that visual interface style. That wasn't pretty hard to achieve. But after that, we wanted something more, so we coded ways of letting the user customize the interface entirely at runtime. This means they could alter the size, position, color, text, etc etc of the buttons and other controls at runtime. Even let the user set some small custom actions that those control did. To make those things possible, the form's load even had a lot of codes to load all the custom settings made by the user for every single control. Imagine that every control had about 20 custom settings to load (as i said, position, color, size, flashing, etc). And also imagine that every form had a few hundred controls. That being said, it self explains why a form would take longer than 10-15 seconds to display. The code inside the load sub looks somehow like this:
For Each obj As LCARSTerminalControls.Controls.ArrowControl In Me.Controls.OfType(Of LCARSTerminalControls.Controls.ArrowControl)()
If regKey.GetValue("ARROWDIRECTION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ArrowDirection = CustomizeModule.ReturnArrowDirection(regKey.GetValue("ARROWDIRECTION_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
If regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString))
obj.Size = New Size(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
If regKey.GetValue("COLOR_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
CustomizeModule.GetControlColor(obj, Me.Name)
End If
If regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Text = CustomizeModule.ControlText(CStr(regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString)))
End If
If regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonTextHeight = CStr(regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonTextAlign = CustomizeModule.ReturnTextAlign(CInt(regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString)))
End If
If regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Flash = CType(regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString), Boolean)
End If
If regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.FlashInterval = CInt(regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Lit = Not CType(regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString), Boolean)
End If
Next
For Each obj As LCARSTerminalControls.Controls.DoublePillControl In Me.Controls.OfType(Of LCARSTerminalControls.Controls.DoublePillControl)()
If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
If regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString))
obj.Size = New Size(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
If regKey.GetValue("COLOR_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
CustomizeModule.GetControlColor(obj, Me.Name)
End If
If regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Text = CustomizeModule.ControlText(CStr(regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString)))
End If
If regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonTextHeight = CStr(regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonTextAlign = CustomizeModule.ReturnTextAlign(CInt(regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString)))
End If
If regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Flash = CType(regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString), Boolean)
End If
If regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.FlashInterval = CInt(regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Lit = Not CType(regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString), Boolean)
End If
Next
For Each obj As LCARSTerminalControls.Controls.ElbowControl In Me.Controls.OfType(Of LCARSTerminalControls.Controls.ElbowControl)()
If regKey.GetValue("ELBOWSTYLE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ElbowControlStyle = CustomizeModule.ReturnElbowStyle(regKey.GetValue("ELBOWSTYLE_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("BUTTONHEIGHT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonHeight = CInt(regKey.GetValue("BUTTONHEIGHT_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("BUTTONWIDTH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonWidth = CInt(regKey.GetValue("BUTTONWIDTH_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
If regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString))
obj.Size = New Size(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
If regKey.GetValue("COLOR_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
CustomizeModule.GetControlColor(obj, Me.Name)
End If
If regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Text = CustomizeModule.ControlText(CStr(regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString)))
End If
If regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonTextHeight = CStr(regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.ButtonTextAlign = CustomizeModule.ReturnTextAlign(CInt(regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString)))
End If
If regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Flash = CType(regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString), Boolean)
End If
If regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.FlashInterval = CInt(regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString))
End If
If regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
obj.Lit = Not CType(regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString), Boolean)
End If
Next
..................................
and that is one of the simplest examples of the codes. Could that be accomplished to be cross - platform? Could that process be speed up by another language (as mentioned above, c++)? Is visual c++ going to make it faster, if using win32 unmanaged code?
#4
Re: vb.net vs. vc++?
Posted 15 January 2013 - 07:10 AM
Right:
rusoaica, on 15 January 2013 - 07:47 AM, said:
This could be a design issue, which no language will help. If you have a code sample, folks can offer suggestions.
rusoaica, on 15 January 2013 - 07:47 AM, said:
This is wrong. Yes, VB.NET managed, but so is much of Windows. Slower than what, exactly? Remember, if you're talking to UI elements in the OS, everyone is then equal.
rusoaica, on 15 January 2013 - 07:47 AM, said:
Yes, they can be faster. But, if you're talking to UI elements, you're back down to that.
rusoaica, on 15 January 2013 - 07:47 AM, said:
Robust is an opinion. Greater control? You're in Windows; ultimately, they are in control. Greater control internally is talking about things like memory management. This can be a double edged sword if you don't know what you're doing.
rusoaica, on 15 January 2013 - 07:47 AM, said:
No, native means it runs directly on the OS. Not the framework, but still windows.
rusoaica, on 15 January 2013 - 07:47 AM, said:
Yep. You're talking to the OS. You'll be reinventing the wheel and it will take some time...
rusoaica, on 15 January 2013 - 07:47 AM, said:
Not necessarily. Definitely not if you're doing custom controls for Windows API. You could do C++ with something like Qt and then be cross-platform. You'd essentially need a middle tier for your UI logic.
rusoaica, on 15 January 2013 - 07:47 AM, said:
It's all or nothing. You want native C++ or C++.NET? Hint, you never want C++.NET.
Hope this helps.
#5
Re: vb.net vs. vc++?
Posted 15 January 2013 - 07:16 AM
rusoaica, on 15 January 2013 - 09:05 AM, said:
Crap, are those all registry reads? Why aren't you reading that stuff in once and only once? You seem to be reading most of them twice.
I would try this without the registry hits and see how fast it gets.
#6
Re: vb.net vs. vc++?
Posted 15 January 2013 - 09:12 AM
For Each obj As LCARSTerminalControls.Controls.ArrowControl
and
For Each obj As LCARSTerminalControls.Controls.ElbowControl
Those are two different controls, with some different properties. For example, the arrow button control has the property named "arrow dirrection", which the elbow button control does not have. Also, the elbow has the elbow style property, which is not present for the rest of the controls. Thats why it may seem that is repeating, but because they have different properties, i had to take each type of controls and load its settings....
I'm not sure what you meant by "without registry hits". If you mean how it is loading all the controls WITHOUT the custom settings applied by the users, they load fine (3-4 seconds for each form)...
#7
Re: vb.net vs. vc++?
Posted 15 January 2013 - 09:29 AM
This smells of bad architecture.
I mean why are these user controls (they are user controls, right?) not doing all the work themselves.. for their own data?
Are you telling me anything that has a bit of color on the startrek interface is loaded up in the main? Dear lord that must be a mess.
Just off the bat I see things like grids, checkbox lists, panels, menus, etc that should be their own control so.. you know.. in the future you just drag and drop them out of your toolbox.
#8
Re: vb.net vs. vc++?
Posted 15 January 2013 - 09:48 AM
This is the way i was thinking to implement this feature of letting the user set some properties at runtime. Lets take for example, the position of a button. When the user right click on a button, it can drag it across the screen. In the mouse up event, there is a piece of code that stores in the registry a key with the name of the form which is the parent of the button, and the name of the button. Something like this: POSITION_Form1Button1. The value of this key is the new position where the button was dropped. I included the name of the parent form and the name of the button because there might be two forms: form1 and form2, which could both have a Button called Button1, and the program wouldnt know for which one of them is the registry key Position_... So, in the load event of the form1, i put that piece of code, which takes all the controls inside it, read the values of the registry keys and sets the position of the controls according to them:
If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
Is my approach faulty? Is there a better way to let the user set all the properties of a control at runtime and load them again when the program starts? A demonstration of my program can be found here, the archive named "LCARS Terminal".
#9
Re: vb.net vs. vc++?
Posted 15 January 2013 - 09:53 AM
#10
Re: vb.net vs. vc++?
Posted 15 January 2013 - 10:07 AM
Let each user control deal with loading it's image.. and dealing with their events for a sound click.. and so forth.
Things like the 'red alert' property would be an event the controls would catch (after it is raised) and act accordingly.
Then.. even with things in one control.. you are not using some of the obvious cheats.. like drawing of the buttons and what not.. why not pass the graphics object from the main form down to everyone? If things were separate you could easily just make the bitmap memory chunk once (at the start of the app) and not recreate it every time you draw.
So the other question is what is the point of your app? Does it do something specific? Why is the user changing the button location?
#11
Re: vb.net vs. vc++?
Posted 15 January 2013 - 10:29 AM
This post has been edited by rusoaica: 15 January 2013 - 10:30 AM
#12
Re: vb.net vs. vc++?
Posted 15 January 2013 - 10:39 AM
If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
End If
This is one hit:
Dim objLocationValue = regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString)
If objLocationValue IsNot Nothing Then
Dim SavedPosition As String = CStr(objLocationValue)
obj.Location = New Point(CInt(SavedPosition.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.Substring(SavedPosition.IndexOf(",") + 1)))
End If
I would use a caching object for this, so I could just pass the parts that change:
REM PropertyMangager - a custom object to cache values and abstract access REM PropertyInstanceMangager - a custom object used for a given form Dim Pim As PropertyInstanceMangager = PropertyMangager.GetManager(Me.Name) obj.ArrowDirection = Pim.Get(obj.ArrowDirection, obj, "ARROWDIRECTION") obj.Location = Pim.Get(obj.Location, obj, "POSITION") obj.Size = Pim.Get(obj.Size, obj, "SIZE") obj.Color = Pim.Get(obj.Color, obj, "COLOR") obj.Text = Pim.Get(obj.Text, obj, "TEXT")
The idea here is pretty straight forward. You pass the default value, which also gives the object context, Point, Text, etc. You pass the object itself, mostly for name, you could probably skip that, and then you pass the property name. Your object does the lookup. If this has already been looked up, you just pass back the value. If never looked up, you try to look it up. You store the retrieved value or default value if none was retrieved. You pass back the value.
There are a number of ways to do this, but the most important element here is that the UI part of your code is freed from worrying about it and you never lookup twice. In the guts of your PropertyMangager implementation, you can decide where those values are persisted. It needn't, and probably shouldn't, be the registry.
#13
Re: vb.net vs. vc++?
Posted 15 January 2013 - 10:43 AM
Quote
That adds some context, but I hope the "daily basics" is discretely defined.
Quote
That seems like a tall order. Why not reskin a linux OS? I mean let's face it. .this is just an app sitting ontop of windows... mimicking features are fine, but trying to mask (and not re-theme) it will just butt up against it harder.
Quote
Break things down into user controls. Review how you are loading your bitmaps.. minimize having to load a hundred things over and over and over again.
[quote]So, a lot of these users asked for the customization feature, [quote]
Some days you gotta say 'no'.
Quote
I am not sure what I am supposed to be getting out of that clip. I mean look at all the UI panels - those are darn static. Having people throw things all willy nilly like definite runs against the grain. It would almost be worth working in discrete screens.
#14
Re: vb.net vs. vc++?
Posted 15 January 2013 - 10:58 AM
@modi123_1 - even if the idea of having an "LCARS" OS was pretty appealing to us from the beginning, none of us have experience with Linux. Also, there aren't much users ready to start learning it and give up windows (even if Windows sucks, i know
I will also try to "break them into user controls" as you said, even if i dont fully comprehend what you meant by that. As i said, any piece of advice from a more experienced programmer is very welcome!
As for the video, i was mainly referring to the functionality of such a computer, its easiness in usage. For the visual part, i guess you must be a trekkie fanatic to see its simplicity and beauty
This post has been edited by rusoaica: 15 January 2013 - 10:59 AM
#15
Re: vb.net vs. vc++?
Posted 15 January 2013 - 11:08 AM
Quote
For Pete's sake.. user controls. You know.. you are in your project.. you right click on the solution -> add -> user controls.
You know.. using objects and compartmentalizing your logic.
Quote
That sounds like a bit of lazy project management. If a ton of people are throwing suggestions then it's your job, as the project gate keepers, to sort out feasible from not... widely used updates vs single one offs.. good ideas from bad.. etc. Guide the build and don't let the whims of the masses bloat and destroy it.
Quote
Again.. they have fairly static screens across the board. Hence why they can get away with making swoopie curved panel outlines and such.
|
|

New Topic/Question
Reply




MultiQuote








|