Guest:
Register
|
Login
|
Member List
|
Search
|
Statistics
|
FAQ
Language
----------
Simplifed Chinese
Traditional Chinese
English
CnPack Forum
»
技术板块灌水区
» 问一个看似很平常的问题
‹‹ Last Thread
|
Next Thread ››
Poll
Trade
Reward
Activity
Printable Version
|
Email to Friend
|
Subscription
|
Favorites
Subject: 问一个看似很平常的问题
niaoge
灌水司司长
UID 9910
Digest Posts 0
Credits 438
Posts 143
点点分 438
Reading Access 10
Registered 2007-4-8
Status Offline
#1
Post at 2007-7-30 11:58
Profile
|
Blog
|
P.M.
问一个看似很平常的问题
下例两种方法有区别吗?
1.
begin
with TXXObject.create() do
try
......
finally
Free
end;
end
2.
var
XXX:TXXObject
begin
XXX:=TXXObject.create()
with XXX do
try
......
finally
FreeAndNil(XXX);
end;
大家不要笑话我啊
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#2
Post at 2007-7-30 15:45
Profile
|
Blog
|
P.M.
从实现效果上来说没有区别。
从编译器生成的代码来说,可能有点区别。后者使用了堆栈中的局部变量,而前者可能只使用某个寄存器。
stanleyxu2005
新警察
UID 5617
Digest Posts
1
Credits 45
Posts 15
点点分 45
Reading Access 10
Registered 2007-2-11
Status Offline
#3
Post at 2007-7-31 17:09
Profile
|
Site
|
Blog
|
P.M.
第一种方法比较干净,而且生成的代码更简洁
http://getgosurf.com/forum/
Rainstorey
普通灌水员
菜鸟
UID 977
Digest Posts 0
Credits 82
Posts 39
点点分 82
Reading Access 10
Registered 2005-8-8
Location 苏州
Status Offline
#4
Post at 2007-7-31 17:21
Profile
|
Blog
|
P.M.
第一种方法构建的是临时对象,放在CPU寄存器中接下来对类的成员访问都是通过寄存器直接寻址所以速度比较快.缺点是出了With的作用域寄存器恢复上下问你也就失去了对类的访问能力.
第二种方法是把类的引用地址存入栈变量(类的实体内容是存放在堆中),这样通过变量来访问类成员.速度比起第一种通常要要慢一些.(内存访问,不排除被编译器优化).好处是访问类的能力即为该变量的存活期.
http://www.RainCoding.com/blog
zzzl
(早安的空气)
版主
UID 590
Digest Posts 0
Credits 399
Posts 199
点点分 399
Reading Access 100
Registered 2004-11-29
Status Offline
#5
Post at 2007-8-2 08:45
Profile
|
Blog
|
P.M.
|
区别就是看起来不一样
Poll
Trade
Reward
Activity
CnPack Forum
CnPack English Forum
> CnWizards IDE Wizards
> CVSTracNT
> Announcements & Others
All times are GMT++8, the time now is 2024-11-23 06:06
Powered by
Discuz!
5.0.0
© 2001-2006
Comsenz Inc.
Processed in 0.014485 second(s), 9 queries , Gzip enabled
TOP
Clear Cookies
-
Contact Us
-
CnPack Website
-
Archiver
-
WAP
Member's CP Home
Edit Profile
Credits Transaction
Public User Groups
Buddy List
Main
Page Views
User Agents
Posts History
Top Forums
Top Threads
Post Ranking
Credit Ranking
Online Time
Team
Moderation Stats