惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 苹果王子

c++ 属性 一维动态数组类模板 加密技术(学习笔记四矩阵加密) 窗口 交互 窗口的方法 加密技术(学习笔记三)Replace 加密技术(学习笔记=)Caesar算法 加密技术(学习笔记一) net2008+sql2008 安装问题指南 补丁更新服务器二(多线程下载+进度条) Thread交叉访问的问题..... 随便写点c++学习笔记 补丁更新服务器一 领带的打法 爱程序有错吗? ASP.NET....为能开始侦听端口的解决办法 轻松一下(添加参数的烦恼) 只为今天(转)希望之源 数据访问框架(正在商业应用中的- -) - -从头在来
学习笔录-ref
苹果王子 · 2007-09-24 · via 博客园 - 苹果王子

今天在 WekeRoad.ActionPack里面看到如下

ApplyConfig(config, ref regexIgnoreCase, ConfigurationPropertyName.REGEX_IGNORE_CASE);


private static void ApplyConfig(System.Collections.Specialized.NameValueCollection config, ref string parameterValue, string configName)
        
{
            
if (config[configName] != null)
            
{
                parameterValue 
= config[configName].ToString();
            }

        }

注意他 ref string---据我所知首先string 是引用类型,本身是按引用传递的~~那为什么他么这样写那
-------------------
于是我做了测试

   public static void s(String s)
       
{
           Console.Write(s);
       }



.method public hidebysig static void  s(string s) cil managed
{
  // 代码大小       9 (0x9)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldarg.0=Loads the argument at index 0 onto the evaluation stack.//--加载 这个参数 他的索引是0在堆栈上

  IL_0002:  call       void [mscorlib]System.Console::Write(string)
  IL_0007:  nop
  IL_0008:  ret
} // end of method MyProcessClass::s

     public static void s1(ref String s)
       
{
           Console.WriteLine(s);
      
       }

.method public hidebysig static void  s1(string& s) cil managed
{
  // 代码大小       10 (0xa)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_0002:  ldind.ref=Loads an object reference as a type O (object reference) onto the evaluation stack indirectly
//--加载一个对象的引用他的类型被看作是跟0一样的 这个类型(对象引用) 在 这个堆栈上
  IL_0003:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_0008:  nop
  IL_0009:  ret
} // end of method MyProcessClass::s1
- -这样多做一步对引用类型来说没什么好处哈哈..我估计这里写错了呵呵
--在做压力测试的时候-两种写发所用时间相同- -0

----------------------------于是我对值类型的又测试了下


 
public static void s123(cc1 c)
       
{

           Console.WriteLine(c.c);
       }


.method public hidebysig static void  s123(valuetype Process_Sample.MyProcessClass/cc1 c) cil managed
{
  // 代码大小       15 (0xf)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldarga.s   c =Load an argument address, in short form, onto the evaluation stack.
                                  ldarga.s xx,即,读出参数xx的地址并压栈

 IL_0003:  ldfld      int32 Process_Sample.MyProcessClass/cc1::c
  IL_0008:  call       void [mscorlib]System.Console::WriteLine(int32)
  IL_000d:  nop
  IL_000e:  ret
} // end of method MyProcessClass::s123

 public static void s1234(ref cc1 c)
       
{

           Console.WriteLine(c.c);
       }

.method public hidebysig static void  s1234(valuetype Process_Sample.MyProcessClass/cc1& c) cil managed
{
  // 代码大小       14 (0xe)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ldarg.0//-//--加载 这个参数 他的索引是0在堆栈上
  IL_0002:  ldfld      int32 Process_Sample.MyProcessClass/cc1::c
  IL_0007:  call       void [mscorlib]System.Console::WriteLine(int32)
  IL_000c:  nop
  IL_000d:  ret
} // end of method MyProcessClass::s1234

//--如果我没有翻译错的话
那么方法1不如方法2直接就可以使用参数,而必须读出这个参数有点像加载
且压力测试中ref总是速度快- -
---最后是关于上面两个方法的调用


  s123(c22);
      
  IL_0033:  ldloc.2//--ldloc.2=Loads the local variable at index 2 onto the evaluation stack.
//--加载变量

  IL_0034:  call       void Process_Sample.MyProcessClass::s123(valuetype Process_Sample.MyProcessClass/cc1)
  IL_0039:  nop


    s1234(ref c22);

  IL_003a:  ldloca.s   c22 //--ldloca.s=Loads the address of the local variable at a specific index onto the evaluation stack, short form.--加载地址
  IL_003c:  call       void Process_Sample.MyProcessClass::s1234(valuetype Process_Sample.MyProcessClass/cc1&)
  IL_0041:  nop