属性或参数:性能最佳的是什么? [英] Properties or parameters : what's best performing?

查看:52
本文介绍了属性或参数:性能最佳的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


当我开始使用VB6时,我曾经写过带有属性的类和

函数如下......


私有lngf1为长

私有strf2为字符串


公共属性获取f1()为长

f1 = lngf1

结束物业


公共财产让f1(ByVal vnewvalue As Long)

lngf1 = vnewvalue

结束属性


....


公共函数DLInsertData(ConnStr As String,Provider As String))as as很长

错误GoTo Errorhandler

Dim cnDB As ADODB.Connection

Dim cmQ1 as ADODB.Command

Set cnDB =新的ADODB.Connection

cnDB.Provider = parProvider

cnDB.ConnectionString = parConnStr

cnDB.ConnectionTimeout = 10

cnDB.Open

设置cmQ1 =新ADODB.Command

设置cmQ1.ActiveConnection = cnDB

cmQ1.CommandType = adCmdStoredProc

cmQ1.Com mandText =" xx"

cmQ1.Parameters.Refresh

cmQ1.Parameters(1).Value = f1

cmQ1.Parameters(2 ).Value = f2

...等

cmQ1.Execute

DLInsertadvstabl = cmQ1.Parameters(45).Value

cnDB.Close

设置cnDB =没什么

退出函数

错误处理程序:

Err.Raise Err.Number,Err.Source,Err.Description

结束函数


所以我填写了类本身以外的属性,主要是通过赋值

形成属性的控制值,然后调用函数将数据插入数据库。


后来我学会了避免财产VB6类中的声明。有人告诉我

使用参数。所以我有没有属性的类,带有

函数的类,有很多像这样的参数...


公共函数DLInsertData(ConnStr As String,Provider As String,field1

As Long,field2 as string,etc)as Long

On Error GoTo Errorhandler

Dim cnDB As ADODB.Connection

Dim cmQ1作为ADODB.Command

设置cnDB =新ADODB.Connection

cnDB.Provider = parProvider

cnDB。 ConnectionString = parConnStr

cnDB.ConnectionTimeout = 10

cnDB.Open

设置cmQ1 =新ADODB.Command

设置cmQ1.ActiveConnection = cnDB

cmQ1.CommandType = adCmdStoredProc

cmQ1.CommandText =" xx"

cmQ1.Parameters.Refresh

cmQ1.Parameters(1).Value = field1

cmQ1.Parameters(2).Value = field2

... etc

cmQ1.Execute

DLInsertadvstabl = cmQ1.Parameters(45).Value

cnDB.Close

设置cnDB =没有什么

退出功能

错误处理程序:

Err.Raise Err.Number,Err.Source,Err.Description

结束功能


据我所知,一旦DLL必须在n层环境中使用
,这应该更加美好MTS或COM +。我相信系统有
来为多个用户实例化的所有对象的属性保留空间,这可能会占用内存并与COM +原则发生冲突。

没有人确认过这个理论,我当时并不需要知道

当时的所有答案。


但是现在我开始使用ASP.NET了,我必须为更大的应用程序编写VB.NET代码,我想制作最好的代码。所以现在我想知道

上面的理论是否正确以及它是否也可以用点网提醒




那么,COM +仍然是dot net中的一个问题吗?

那么,我可以在ASP.NET中使用基于属性的对象吗?

或者我应该避免使用.vb中的属性使用

参数的类和使用函数以获得最佳性能?


非常感谢。


-

亲切的问候,

Perre Van Wilrijk,

删除大写字母以获取我的真实电子邮件地址,

Hi there,

When I started using VB6, I used to write classes with properties and
functions as following ...

Private lngf1 As Long
Private strf2 As String

Public Property Get f1() As Long
f1 = lngf1
End Property

Public Property Let f1(ByVal vnewvalue As Long)
lngf1 = vnewvalue
End Property

....

Public Function DLInsertData(ConnStr As String, Provider As String)) as Long
On Error GoTo Errorhandler
Dim cnDB As ADODB.Connection
Dim cmQ1 As ADODB.Command
Set cnDB = New ADODB.Connection
cnDB.Provider = parProvider
cnDB.ConnectionString = parConnStr
cnDB.ConnectionTimeout = 10
cnDB.Open
Set cmQ1 = New ADODB.Command
Set cmQ1.ActiveConnection = cnDB
cmQ1.CommandType = adCmdStoredProc
cmQ1.CommandText = "xx"
cmQ1.Parameters.Refresh
cmQ1.Parameters(1).Value = f1
cmQ1.Parameters(2).Value = f2
... etc
cmQ1.Execute
DLInsertadvstabl = cmQ1.Parameters(45).Value
cnDB.Close
Set cnDB = Nothing
Exit Function
Errorhandler:
Err.Raise Err.Number, Err.Source, Err.Description
End Function

So I populated the properties outside the class itself, mostly by assigning
form control values to the properties, followed by calling the function to
insert data into the database.

Later on I learned to avoid property declaration in VB6 Classes. I was told
to use parameters. So I had classes without properties, classes with
functions with lot of parameters like this one ...

Public Function DLInsertData(ConnStr As String, Provider As String, field1
As Long, field2 as string, etc) as Long
On Error GoTo Errorhandler
Dim cnDB As ADODB.Connection
Dim cmQ1 As ADODB.Command
Set cnDB = New ADODB.Connection
cnDB.Provider = parProvider
cnDB.ConnectionString = parConnStr
cnDB.ConnectionTimeout = 10
cnDB.Open
Set cmQ1 = New ADODB.Command
Set cmQ1.ActiveConnection = cnDB
cmQ1.CommandType = adCmdStoredProc
cmQ1.CommandText = "xx"
cmQ1.Parameters.Refresh
cmQ1.Parameters(1).Value = field1
cmQ1.Parameters(2).Value = field2
... etc
cmQ1.Execute
DLInsertadvstabl = cmQ1.Parameters(45).Value
cnDB.Close
Set cnDB = Nothing
Exit Function
Errorhandler:
Err.Raise Err.Number, Err.Source, Err.Description
End Function

As far as I remember this should be much beter once the DLL''s had to be
placed in n-tier environments using MTS or COM+. I believe the system has
to reserve space for the properties of all the objects instanceiated by the
multiple users and that might eat memory and conflict with COM+ principles.
Nobody has ever confirmed me this theory and I didn''t really need to know
all the answers at that time.

But now I''m starting to use ASP.NET and I have to write VB.NET code for
larger applications, I want to make the best code I can. So now I wonder
whether the theory above is true and whether it''s also something to remind
in dot net.

So, is COM+ still an issue in dot net?
So, may I use property based objects in ASP.NET?
Or should I avoid properties in .vb classes and use functions with
parameters in order to obtain the best performance?

Thanks a lot.

--
Kind regards,
Perre Van Wilrijk,
Remove capitals to get my real email address,

推荐答案



" Perre Van Wilrijk" < PR **** @ AkoopjeskrantWAY.be>写了

"Perre Van Wilrijk" <pr****@AkoopjeskrantWAY.be> wrote
那么,我可以在ASP.NET中使用基于属性的对象吗?
或者我应该避免.vb类中的属性并使用带有
参数的函数获得最佳性能?
So, may I use property based objects in ASP.NET?
Or should I avoid properties in .vb classes and use functions with
parameters in order to obtain the best performance?




如果你想象你的代码在加利福尼亚州,并且所需的对象是在纽约的b
和两种方式之间发送信息的唯一方法就是给一只鸽子打上一张纸条并将其发送给它......


你要去每当你需要访问一个鸽子时,你会发送一只鸽子,然后在发送另一只鸽子之前等待归来的鸽子吗?

或者你想要写所有的鸽子信息下来

在一张纸条中发送一只鸽子让该物体作出回应?


我的观点是,重要的是什么类型的边界你

计划跨越。 ASP听起来像是在使用互联网,或者至少是某种类型的网络,当然不是本地引用的对象。


在这种情况下,避免繁琐的对象(Chatty =强制要求的电话

正常使用;例如:设置属性),然后去参数化路线。


HTH

LFS



If you imagine your code is in California, and a needed object is in
New York, and the only way to send messages between the two is
to tie a note to a pigeon and send it on its way....

Are you going to send off a pigeon every time you need to access
a property, and then wait for a return pigeon before sending off another?
Or are you going to want to write all the information down
in a note and send off one pigeon to get that object to respond?

The point I am making is that it matters what kinds of boundries you
plan to cross. ASP sounds like you''re using the internet, or at least
a network of some kind, certainly not a locally referenced object.

In that case, avoid chatty objects (Chatty = forcing required calls
for normal use; ex: setting properties), and go the parameterized route.

HTH
LFS


Perre,


我很高兴我不知道你写的所有麻烦,不过也许我可以告诉你什么对我来说VBNet ASPNET应用程序是为了让你更多

清楚。 (我不知道你是否曾经尝试过VB6中的IIS项目,而不是你已经想到了这个想法)


当你使用ASPNET时脚本方式你实际上和

经典ASP一样。


但是当你使用VBNet创建它作为ASPNET项目而不是你创建

a DLL。


该DLL是您的中间层。它是活动的,只要有用户活动

并且是一个由所有活跃用户共享的应用程序(事实上有点

更长,具体取决于页面发送回等待时间)。

您的网页是客户端,与该应用程序进行交互。

该应用程序在网页上提供信息时提供信息
通过回复邮件,每次在应用程序中创建一个页面

并且只要它不再重新回到客户端就可以了。在经典的

ASP中,我称之为我的Com对象,我必须在服务器上注册。


ASPNET使用静止会话来保存信息,但同样如此你有这个视频状态(发送给客户端的信息是什么,并通过回发将其返回给b $ b)有一个属于所有客户端的缓存,并且有

共享类,它们也属于所有客户端。因此,对于最后两个你来说,当你持有

个人客户的信息时,你需要做的事情与过去一样。你也可以使用普通的类(对象)。

这些普通类的范围只要页面在服务器端,

比所有信息都要销毁从那个。


如果你使用属性或参数在我的

意见中并不那么重要,只能处理大约纳秒。当我开始序列化你的数据对象时,这就成了我的意见




也许你已经知道了这一点,但我不知道什么时候看到你的

留言。


只是我的想法。


Cor


Perre,

I am glad I don''t know all those troubles you write, however maybe can I
tell you what for me a VBNet ASPNET application is to make it you more
clear. (I don''t know if you ever tried the IIS project in VB6, than you have
already the idea)

When you use ASPNET in a scripting way you are in fact doing the same as
classic ASP.

However when you create it as an ASPNET project using VBNet than you create
a DLL.

That DLL is your middle tier. It is active as long as there are users active
and is an application shared by all active users (in fact a little bit
longer depending on the page sent back wait time).

Your webpages are the clientside, which interacts with that application.
That application gives information to the webpages, when they ask for that
by doing a post back, a page is than everytime created in the application
and is there as long as it is not again sand back to the client. In classic
ASP I called this my Com object that I had to register on the server.

ASPNET uses still sessions to hold the information, however as well you have
the viewstate (what does the information sent to the client and gets it back
with a postback) there is a cache which belongs to all clients and there are
shared classes which belong as well to all clients. For the last two you
have therefore to do all the same as in past when you hold information for
individual clients in that. You can as well use normal classes (objects).
The scope of those normal classes is as long as a page is on the serverside,
than all information will be destroyed from that.

If you use properties or parameters is not so important in this in my
opinion and only dealing about nanoseconds. That becomes in my opininion
important when you start serializing your dataobjects.

Maybe you know this above already, however I was not sure when I saw your
message.

Just my thoughts.

Cor



Larry,


我开始尝试在卡片游戏中使用你的课程,但是我想要b / b
将它们翻译成C#。


Cor
Larry,

I started with trying to use your classes in the cardgame, however I am
trying to translate them to C#.

Cor


这篇关于属性或参数:性能最佳的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆