当前位置: 首页 > 编程日记 > 正文

Mono源代码学习笔记:Console类(四)

NullStream 类 (internal class)

下面就是 mcs/class/corlib/System.IO/NullStream.cs:

01:  namespace System.IO
02:  {
03:    class NullStream : Stream
04:    {
05:      public override bool CanRead { get { return true; } }
06:      public override bool CanSeek { get { return true; } }
07:      public override bool CanWrite { get { return true; } }
08:      public override long Length { get { return 0; } }
09:      public override long Position { get { return 0; } set { } }
10:      public override void Flush() { }
11:      public override int Read(byte[] buffer, int offset, int count) { return 0; }
12:      public override int ReadByte() { return -1; }
13:      public override long Seek(long offset, SeekOrigin origin) { return 0; }
14:      public override void SetLength(long value) { }
15:      public override void Write(byte[] buffer, int offset, int count) { }
16:      public override void WriteByte(byte value) { }
17:    }
18:  }

上述源程序定义了 NullStream 类。我在我个系列学习笔记第一篇中谈到,这个 NullStream 类是从 Stream.cs 中分离出来的,经过我的整理后就变成上面这个样子。从上述的源程序中可以看出:

  1. NullStream 类位于 System.IO 命名空间中。(第 1 行)
  2. NullStream 继承自抽象基类 Stream。(第 3 行)
  3. NullStream 是个 internal 类,只能用在本程序集中。(第 3 行)
  4. NullStream 有 12 个成员,全部是公共成员,用于重写抽象基类 Stream 的虚成员。(5 - 16 行)
  5. NullStream 有 5 个属性。这些属性的 get 方法仅返回零或者 true,仅有的一个 set 方法是空的。(5 - 9行)
  6. NullStream 有 7 个方法,这方法要么是空的,要么仅返回零或者 -1。(10 – 16 行)

NullStream 类实践了 Null Object 设计模式。

由于 NullStream 类是作为 Null Object 使用的,它可以不重写抽象基类 Stream 的 ReadByte 方法(第 12 行)和 WriteByte 方法(第 16 行),因为 Stream 的这两个方法都是虚(virtual)方法,而不是抽象(abstract)方法。下面就是 Mono 源代码中的 mcs/class/corlib/System.IO/Stream.cs 文件中 Stream 类的这两个虚方法的代码:

01:  public virtual int ReadByte()
02:  {
03:    byte[] buffer = new byte[1];
04:    if (Read(buffer, 0, 1) == 1) return buffer[0];
05:    return -1;
06:  }
07:  
08:  public virtual void WriteByte(byte value)
09:  {
10:    byte[] buffer = new byte[1];
11:    buffer[0] = value;
12:    Write(buffer, 0, 1);
13:  }

可以看出,Stream 类的 ReadByte 方法创建一个新的单字节数组,然后调用 Read 方法(第 3 行到第 5 行)。Stream 类的 WriteByte 方法创建一个新的单字节数组,然后调用 Write 方法(第 10 行到第 12 行)。也就是说,如果 NullStream 类不重写抽象基类 Stream 的 ReadByte 方法和 WriteByte 方法,得到的运行结果也是一样的。但是,这样效率就低了很多。

在 Console.dll 项目中,NullStream 类仅在 Console.cs 中被使用过一次。

对 NullStream 类的改进建议

我建议将 mcs/class/corlib/System.IO/NullStream.cs 改为如下所示:

01:  namespace System.IO
02:  {
03:    partial class Stream
04:    {
05:      private sealed class NullStream : Stream
06:      {
07:        public override bool CanRead { get { return true; } }
08:        public override bool CanSeek { get { return true; } }
09:        public override bool CanWrite { get { return true; } }
10:        public override long Length { get { return 0; } }
11:        public override long Position { get { return 0; } set { } }
12:        public override void Flush() { }
13:        public override int Read(byte[] buffer, int offset, int count) { return 0; }
14:        public override int ReadByte() { return -1; }
15:        public override long Seek(long offset, SeekOrigin origin) { return 0; }
16:        public override void SetLength(long value) { }
17:        public override void Write(byte[] buffer, int offset, int count) { }
18:        public override void WriteByte(byte value) { }
19:      }
20:    }
21:  }

也就是说,将 NullStream 类从 System.IO 命名空间中的 internal 类更改为 System.IO.Stream 类的私有(private)密封(sealed)内嵌类(请参阅上述源程序第 5 行)。而 mcs/class/corlib/System.IO/Stream.cs 只需作如下改动:

01:  namespace System.IO
02:  {
03:    [Serializable]
04:    [ComVisible(true)]
05:    public abstract partial class Stream : MarshalByRefObject, IDisposable
06:    {
07:      public static readonly Stream Null = new NullStream();
08:  
09:      //
10:      // 这里省略 Stream 类的其余成员
11:      //
12:    }
13:  }

如上述源程序第 5 行所示,加上 partial 关键字就行了。

第 7 行通过 Stream 类的 Null 公共只读静态字段对外公开了 NullStream 类。注意,这是 Stream.cs 中原来的代码,我没有作任何改动。

现在,其他程序要使用 NullStream 类,只有通过 Stream.Null 字段来使用了,这也是 NullStream 类的唯一实例。在我们的 Console.cs 中,原来是通过 new NullStream() 来使用 NullStream 类的,现在需要改为 Stream.Null 了。

这样做的好处是显而易见的:

  1. 我们对外隐藏了 NullStream 类,大家只需要知道 Stream.Null 这个公共只读静态字段好了。
  2. NullStream 类只被实例化一次,提高了效率。
  3. NullStream 类被声明为 sealed 的,可能对 C# 编译器以及 JIT 优化调用该类的虚方法的语句有好处。例如,有可能使用 call 指令代替 callvirt 指令。

这也实践了 Singleton 设计模式和 Null Object 设计模式。

UnexceptionalStreamReader 类 (internal class)

下面就是 mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs:

001:  //
002:  // System.IO.UnexceptionalStreamReader.cs
003:  //
004:  // Authors:
005:  //   Dietmar Maurer (dietmar@ximian.com)
006:  //   Miguel de Icaza (miguel@ximian.com)
007:  //   Dick Porter (dick@ximian.com)
008:  //   Sebastien Pouliot  <sebastien@ximian.com>
009:  //
010:  // (C) Ximian, Inc.  http://www.ximian.com
011:  // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
012:  //
013:  // Permission is hereby granted, free of charge, to any person obtaining
014:  // a copy of this software and associated documentation files (the
015:  // "Software"), to deal in the Software without restriction, including
016:  // without limitation the rights to use, copy, modify, merge, publish,
017:  // distribute, sublicense, and/or sell copies of the Software, and to
018:  // permit persons to whom the Software is furnished to do so, subject to
019:  // the following conditions:
020:  // 
021:  // The above copyright notice and this permission notice shall be
022:  // included in all copies or substantial portions of the Software.
023:  // 
024:  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
025:  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
026:  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
027:  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
028:  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
029:  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
030:  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
031:  //
032:  
033:  
034:  // This is a wrapper around StreamReader used by System.Console that
035:  // catches IOException so that graphical applications don't suddenly
036:  // get IO errors when their terminal vanishes.  See
037:  // UnexceptionalStreamWriter too.
038:  
039:  using System.Text;
040:  using System.Runtime.InteropServices;
041:  
042:  namespace System.IO {
043:      internal class UnexceptionalStreamReader : StreamReader {
044:  
045:          private static bool[] newline = new bool [Environment.NewLine.Length];
046:  
047:          private static char newlineChar;
048:  
049:          static UnexceptionalStreamReader () {
050:              string n = Environment.NewLine;
051:              if (n.Length == 1)
052:                  newlineChar = n [0];
053:          }
054:  
055:          public UnexceptionalStreamReader(Stream stream)
056:              : base (stream)
057:          {
058:          }
059:  
060:          public UnexceptionalStreamReader(Stream stream, bool detect_encoding_from_bytemarks)
061:              : base (stream, detect_encoding_from_bytemarks)
062:          {
063:          }
064:  
065:          public UnexceptionalStreamReader(Stream stream, Encoding encoding)
066:              : base (stream, encoding)
067:          {
068:          }
069:  
070:          public UnexceptionalStreamReader(Stream stream, Encoding encoding, bool detect_encoding_from_bytemarks)
071:              : base (stream, encoding, detect_encoding_from_bytemarks)
072:          {
073:          }
074:          
075:          public UnexceptionalStreamReader(Stream stream, Encoding encoding, bool detect_encoding_from_bytemarks, int buffer_size)
076:              : base (stream, encoding, detect_encoding_from_bytemarks, buffer_size)
077:          {
078:          }
079:  
080:          public UnexceptionalStreamReader(string path)
081:              : base (path)
082:          {
083:          }
084:  
085:          public UnexceptionalStreamReader(string path, bool detect_encoding_from_bytemarks)
086:              : base (path, detect_encoding_from_bytemarks)
087:          {
088:          }
089:  
090:          public UnexceptionalStreamReader(string path, Encoding encoding)
091:              : base (path, encoding)
092:          {
093:          }
094:  
095:          public UnexceptionalStreamReader(string path, Encoding encoding, bool detect_encoding_from_bytemarks)
096:              : base (path, encoding, detect_encoding_from_bytemarks)
097:          {
098:          }
099:          
100:          public UnexceptionalStreamReader(string path, Encoding encoding, bool detect_encoding_from_bytemarks, int buffer_size)
101:              : base (path, encoding, detect_encoding_from_bytemarks, buffer_size)
102:          {
103:          }
104:  
105:          public override int Peek ()
106:          {
107:              try {
108:                  return(base.Peek ());
109:              } catch (IOException) {
110:              }
111:  
112:              return(-1);
113:          }
114:  
115:          public override int Read ()
116:          {
117:              try {
118:                  return(base.Read ());
119:              } catch (IOException) {
120:              }
121:  
122:              return(-1);
123:          }
124:  
125:          public override int Read ([In, Out] char[] dest_buffer,
126:                        int index, int count)
127:          {
128:              if (dest_buffer == null)
129:                  throw new ArgumentNullException ("dest_buffer");
130:              if (index < 0)
131:                  throw new ArgumentOutOfRangeException ("index", "< 0");
132:              if (count < 0)
133:                  throw new ArgumentOutOfRangeException ("count", "< 0");
134:              // ordered to avoid possible integer overflow
135:              if (index > dest_buffer.Length - count)
136:                  throw new ArgumentException ("index + count > dest_buffer.Length");
137:  
138:              int chars_read = 0;
139:              char nl = newlineChar;
140:              try {
141:                  while (count > 0) {
142:                      int c = base.Read ();
143:                      if (c < 0)
144:                          break;
145:                      chars_read++;
146:                      count--;
147:  
148:                      dest_buffer [index] = (char) c;
149:                      // shortcut when a new line is only one character (e.g. Linux, Mac)
150:                      if (nl != (char)0) {
151:                          if ((char)c == nl)
152:                              return chars_read;
153:                      } else {
154:                          if (CheckEOL ((char)c))
155:                              return chars_read;
156:                      }
157:                      index ++;
158:                  }
159:              } catch (IOException) {
160:              }
161:              
162:              return chars_read;
163:          }
164:  
165:          private bool CheckEOL (char current)
166:          {
167:              // general case for any length (e.g. Windows)
168:              for (int i=0; i < newline.Length; i++) {
169:                  if (!newline [i]) {
170:                      if (current == Environment.NewLine [i]) {
171:                          newline [i] = true;
172:                          return (i == newline.Length - 1);
173:                      }
174:                      break;
175:                  }
176:              }
177:              for (int j=0; j < newline.Length; j++)
178:                  newline [j] = false;
179:              return false;
180:          }
181:  
182:          public override string ReadLine()
183:          {
184:              try {
185:                  return(base.ReadLine ());
186:              } catch (IOException) {
187:              }
188:  
189:              return(null);
190:          }
191:  
192:          public override string ReadToEnd()
193:          {
194:              try {
195:                  return(base.ReadToEnd ());
196:              } catch (IOException) {
197:              }
198:  
199:              return(null);
200:          }
201:      }
202:  }

上述源程序定义了 UnexceptionalStreamReader 类。该类位于 System.IO 命名空间中,继承自 StreamReader 类,是 internal 的,即只能在本程序集中使用。

UnexceptionalStreamReader 类是对 StreamReader 类的包装,捕获并忽略所有的 IOException 异常。它用于 Console 类中,以免 IO 错误干扰控制台的正常运行。

UnexceptionalStreamReader 类定义了以下两个私有静态字段:

  1. newline: private static,类型为 bool[]。(第 45 行)
  2. newlineChar: private static,类型为 char。(第 47 行)

第 49 行到第 53 行的静态构造函数对 newlineChar 字段有条件地赋值。

第 55 行到第 103 行的十个构造函数仅是调用基类 StreamReader 相应的构造函数而已。

第 105 行到第 123 行以及第 182 行到第 200 行的四个方法重写了基类 StreamReader 中相应的虚方法,简单地调用基类中相应的虚方法,捕获并忽略 IOException 异常。

第 125 行到第 163 行的 Read 方法也是重写了基类的虚方法,但是它没有简单地调用基类中相应的虚方法。它首先检查输入的参数是否合法,然后在循环中调用基类的另一个 Read 方法一个个地读取字符,捕获并忽略 IOException 异常。注意这个 Read 方法的语义不同于其基类 StreamReader 中相应的 Read 方法的语义,前者遇到 EOL 就提前返回,而后者要遇到 EOF 才会提前返回。

第 165 行到第 180 行的 CheckEOL 方法是私有(private)方法,仅在第 154 行被调用过,用于在 Environment.NewLine 不止一个字符时(在 Windows 操作系统中就是如此,其值为”\r\n”,而在 Unix 操作系统中其值为”\n”)判断是否遇到了行结束符,即 EOL,也就是 Environment.NewLine。

在 Console.dll 项目中,UnexceptionalStreamReader 类在 Console.cs 中被使用过一次。在上述源程序的第 34 行到第 37 行的注释中也已经指出了这一点。

UnexceptionalStreamWriter 类 (internal class)

下面就是 mcs/class/corlib/System.IO/UnexceptionalStreamWriter.cs:

001:  //
002:  // System.IO.StreamWriter.cs
003:  //
004:  // Authors:
005:  //   Dietmar Maurer (dietmar@ximian.com)
006:  //   Paolo Molaro (lupus@ximian.com)
007:  //   Dick Porter (dick@ximian.com)
008:  //
009:  // (C) Ximian, Inc.  http://www.ximian.com
010:  //
011:  
012:  //
013:  // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
014:  //
015:  // Permission is hereby granted, free of charge, to any person obtaining
016:  // a copy of this software and associated documentation files (the
017:  // "Software"), to deal in the Software without restriction, including
018:  // without limitation the rights to use, copy, modify, merge, publish,
019:  // distribute, sublicense, and/or sell copies of the Software, and to
020:  // permit persons to whom the Software is furnished to do so, subject to
021:  // the following conditions:
022:  // 
023:  // The above copyright notice and this permission notice shall be
024:  // included in all copies or substantial portions of the Software.
025:  // 
026:  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
027:  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
028:  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
029:  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
030:  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
031:  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
032:  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
033:  //
034:  
035:  
036:  // This is a wrapper around StreamWriter used by System.Console that
037:  // catches IOException so that graphical applications don't suddenly
038:  // get IO errors when their terminal vanishes (ie when they spew debug
039:  // output.)  See UnexceptionalStreamReader too.
040:  
041:  using System.Text;
042:  using System;
043:  
044:  namespace System.IO {
045:      internal class UnexceptionalStreamWriter: StreamWriter {
046:          public UnexceptionalStreamWriter (Stream stream)
047:              : base (stream)
048:          {
049:          }
050:  
051:          public UnexceptionalStreamWriter (Stream stream,
052:                            Encoding encoding)
053:              : base (stream, encoding)
054:          {
055:          }
056:  
057:          public UnexceptionalStreamWriter (Stream stream,
058:                            Encoding encoding,
059:                            int bufferSize)
060:              : base (stream, encoding, bufferSize)
061:          {
062:          }
063:  
064:          public UnexceptionalStreamWriter (string path)
065:              : base (path)
066:          {
067:          }
068:  
069:          public UnexceptionalStreamWriter (string path, bool append)
070:              : base (path, append)
071:          {
072:          }
073:  
074:          public UnexceptionalStreamWriter (string path, bool append,
075:                            Encoding encoding)
076:              : base (path, append, encoding)
077:          {
078:          }
079:  
080:          public UnexceptionalStreamWriter (string path, bool append,
081:                            Encoding encoding,
082:                            int bufferSize)
083:              : base (path, append, encoding, bufferSize)
084:          {
085:          }
086:  
087:          public override void Flush ()
088:          {
089:              try {
090:                  base.Flush ();
091:              } catch (Exception) {
092:              }
093:          }
094:  
095:          public override void Write (char[] buffer, int index,
096:                          int count)
097:          {
098:              try {
099:                  base.Write (buffer, index, count);
100:              } catch (IOException) {
101:              }
102:          }
103:  
104:          public override void Write (char value)
105:          {
106:              try {
107:                  base.Write (value);
108:              } catch (IOException) {
109:              }
110:          }
111:  
112:          public override void Write (char[] value)
113:          {
114:              try {
115:                  base.Write (value);
116:              } catch (IOException) {
117:              }
118:          }
119:  
120:          public override void Write (string value)
121:          {
122:              try {
123:                  base.Write (value);
124:              } catch (IOException) {
125:              }
126:          }
127:      }
128:  }

上述源程序定义了 UnexceptionStreamWriter 类。该类位于 System.IO 命名空间中,继承自 StreamWriter 类,是 internal 的,即只能在本程序集中使用。

第 2 行的注释“System.IO.StreamWriter.cs”有误,应改为“System.IO.UnexceptionStreamWriter”。

UnexceptionalStreamWriter 类是对 StreamWriter 类的包装,捕获并忽略所有的 IOException 异常。它用于 Console 类中,以免 IO 错误干扰控制台的正常运行。

第 46 行到第 85 行的七个构造函数仅是调用基类 StreamWriter 相应的构造函数而已。

第 87 行到第 126 行的五个方法重写了基类 StreamWriter 中相应的虚方法,简单地调用基类中相应的虚方法,捕获并忽略 IOException 异常。

在 Console.dll 项目中,UnexceptionStreamWriter 类在 Console.cs 中被使用过两次。

(未完待续)

相关文章:

Java帝国对Python的渗透能成功吗?

作者 | 刘欣转载自码农翻身&#xff08;公众号 ID&#xff1a;coderising&#xff09;引子Java 帝国已经成立 20 多年&#xff0c;经过历代国王的励精图治&#xff0c;可以说是地大物博&#xff0c;码农众多。 可是国王依然不满足&#xff0c;整天想着如何继续开拓疆土&#xf…

【杂】突然有个想法,为了防止公司或其他,监视你的qq或微信,可以做个程序,将信息打乱,分别用qq和微信传输,然后,再还原

突然有个想法&#xff0c;为了防止公司或其他&#xff0c;监视你的qq或微信&#xff0c;可以做个程序&#xff0c;将信息打乱&#xff0c;分别用qq和微信传输&#xff0c;然后&#xff0c;再还原。

CTO 基本功大盘点 —— 没有这些技能,谈何远大前程?

本文由 「TGO鲲鹏会」原创&#xff0c;原文链接&#xff1a;CTO 基本功大盘点 —— 没有这些技能&#xff0c;谈何远大前程&#xff1f; 作者&#xff5c;刘海星 2018 年马上就要过去六分之一了&#xff0c;你的 KPI 完成多少了&#xff1f; 别沮丧&#xff0c;其实我想说的是&…

Windows Phone 7 不温不火学习之《创建用户控件》

同样出自微软的产品&#xff0c;像ASP.NET 一样&#xff0c;Windows Phone 7 也有一个叫UserControl 的东西。这个相当于一个组件&#xff0c;类似于Android 继承View 。 本篇将实现一个用户控件&#xff0c;默认为它添加高宽&#xff0c;并为它添加一个自己的事件&#xff0c;…

从起源、变体到评价指标,一文解读NLP的注意力机制

作者 | yuquanle转载自AI小白入门&#xff08;ID:StudyForAI&#xff09;目录1.写在前面2.Seq2Seq 模型3.NLP中注意力机制起源4.NLP中的注意力机制 5.Hierarchical Attention6.Self-Attention7.Memory-based Attention 8.Soft/Hard Attention9.Global/Local Attention10.评价指…

【Git】ubuntu上git commit提交后如何保存和退出类似vim的界面,回到命令行

问题 使用 git commit 命令后&#xff0c;进入类似vim的界面&#xff0c;开始时&#xff0c;不知道如何保存&#xff0c;甚至不知道怎么退出该界面。 解决方法 1、使用 git commit 命令后&#xff0c;进入的是nano文本编辑器&#xff08;类似vim&#xff09;&#xff1b; 2…

linux硬盘满了问题排查

关键指令&#xff1a; df du find step1&#xff1a; 如果发现硬盘满了&#xff0c;首先要确定一下&#xff0c;使用df查看硬盘使用情况 df -h step2&#xff1a; 从第一步结果判定满了&#xff0c;确定哪些文件或哪个文件占了大头&#xff0c;使用du指令做逐步排查&#xff0c…

win2003登陸及關機設定

開啟未登陸可以關機鍵關機﹕ 到控制面板&#xff0c;本地安全策略&#xff0c;安全性選項﹐启用允许在未登录前关机 關關機事件跟踪﹕ 运行“gpedit.msc”命令打开组策略编辑器&#xff0c;依次展开“计算机配置”→“管理模板”→“系统”&#xff0c;将“顯示关闭事件跟踪程序…

【Qt】信号和槽对值传递参数和引用传递参数的总结

在同一个线程中 当信号和槽都在同一个线程中时&#xff0c;值传递参数和引用传递参数有区别&#xff1a; 值传递会复制对象&#xff1b;&#xff08;测试时&#xff0c;打印传递前后的地址不同&#xff09; 引用传递不会复制对象&#xff1b;&#xff08;测试时&#xff0c;…

Node.js入门(含NVM、NPM、NVM的安装)

本文最初发表于博客园&#xff0c;并在GitHub上持续更新前端的系列文章。欢迎在GitHub上关注我&#xff0c;一起入门和进阶前端。 以下是正文。 Node.js的介绍 引擎 引擎的特性&#xff1a; JS的内核即引擎。因为引擎有以下特性&#xff1a; &#xff08;1&#xff09;转化的作…

GitHub日收7000星,Windows计算器项目开源即爆红!

说起此番微软开源 Windows 计算器&#xff0c;有道是“春风得意马蹄疾&#xff0c;一日‘摘星’ 7000”……整理 | 仲培艺来源 | CSDN&#xff08;ID&#xff1a;CSDNnews&#xff09;微软又来给自己拥抱开源的决心送”证明素材“了&#xff01;昨日&#xff0c;微软官宣在 MIT…

域环境下的***

首先还是先简要看一下域的概念吧&#xff1a; 域 (Domain) 是Windows网络中独立运行的单位&#xff0c;域之间相互访问则需要建立信任关系(即Trust Relation)。信任关系是连接在域与域之间的桥梁。当一个域与其他域建立了信任关系后&#xff0c;2个域之间不但可以按需要相互进行…

如何重构“箭头型”代码

本文主要起因是&#xff0c;一次在微博上和朋友关于嵌套好几层的if-else语句的代码重构的讨论&#xff08;微博原文&#xff09;&#xff0c;在微博上大家有各式各样的问题和想法。按道理来说这些都是编程的基本功&#xff0c;似乎不太值得写一篇文章&#xff0c;不过我觉得很多…

让数百万台手机训练同一个模型?Google把这套框架开源了

作者 | 琥珀出品 | AI科技大本营&#xff08;公众号id&#xff1a;rgznai100&#xff09;【导语】据了解&#xff0c;全球有 30 亿台智能手机和 70 亿台边缘设备。每天&#xff0c;这些电话与设备之间的交互不断产生新的数据。传统的数据分析和机器学习模式&#xff0c;都需要在…

【OpenCV】cv::VideoCapture 多线程测试

cv::VideoCapture多线程测试结果&#xff1a; 在多线程中使用抓取摄像头视频帧时线程安全的&#xff0c;但是&#xff0c;多个线程会共用摄像头的总帧率。 比如&#xff0c;我用两个线程测试30帧的摄像头&#xff0c;每个线程差多都是15帧。

都有Python了,还要什么编译器!

编译的目的是将源码转化为机器可识别的可执行程序&#xff0c;在早期&#xff0c;每次编译都需要重新构建所有东西&#xff0c;后来人们意识到可以让编译器自动完成一些工作&#xff0c;从而提升编译效率。但“编译器不过是用于代码生成的软机器&#xff0c;你可以使用你想要的…

【Qt】Qt发布程序时,报错: could not find or load the Qt platform plugin xcb

问题描述 Qt程序在发布时&#xff0c;报错&#xff1a; This application failed to start because it could not find or load the Qt platform plugin “xcb” in “”. Reinstalling the application may fix this problem Aborted (core dumped) 原因 没有将libqxcb…

jsky使用小记

jsky是一款深度WEB应用安全评估工具&#xff0c;能轻松应对各种复杂的WEB应用&#xff0c;全面深入发现里面存在的安全弱点。 jsky可以检测出包括SQL注入、跨站脚本、目录泄露、网页木马等在内的所有的WEB应用层漏洞&#xff0c;渗透测试功能让您熟知漏洞危害。 打开——新建扫…

BSP场景管理方法简介

BSP&#xff08;Binary Space Partition,二叉空间分割&#xff09;方法&#xff0c;在大型3d游戏场景管理方面&#xff0c;可以认为是已经证明了的&#xff0c;最成熟的&#xff0c;最经得起考验的场景管理方法。诸如虚幻系列引擎&#xff08;Unreal 1,2,3&#xff09;&#xf…

【Qt】Qt样式表总结(一):选择器

官方资料 https://blog.csdn.net/u010168781/article/details/81868523 注释 qss文件中使用:/**/ 来注释 样式规则 样式表由样式规则序列组成。样式规则由选择器和声明组成。选择器指定受规则影响的部件;声明指定应在小部件上设置哪些属性。 如: QLabel { color: white;…

JVM-01:类的加载机制

本文从  纯洁的微笑的博客  转载 原地址&#xff1a;http://www.ityouknow.com/jvm.html 类的加载机制 1、什么是类的加载 类的加载指的是将类的.class文件中的二进制数据读入到内存中&#xff0c;将其放在运行时数据区的方法区内&#xff0c;然后在堆区创建一个java.lang.…

CVPR 2019 | 惊艳的SiamMask:开源快速同时进行目标跟踪与分割算法

作者 | 周强&#xff08;CV君&#xff09;来源 | 我爱计算机视觉&#xff08;公众号id&#xff1a;aicvml&#xff09;责编 | Jane上面这张Gif图演示了 SiamMask 的效果&#xff0c;只需要鼠标滑动选择目标的包围框&#xff0c;即可同时实现目标跟踪与分割。这种视频里目标的像…

看看Entity Framework 4生成的复杂的分页SQL语句

之前发现Entity Framework 4生成的COUNT查询语句问题&#xff0c;今天又发现它生成的分页SQL语句问题&#xff0c;而LINQ to SQL却不存在这个问题。 >>> 来看一看&#xff0c;瞧一瞧&#xff01; 上代码&#xff1a; 看生成的SQL语句&#xff1a; 1. Entity Framework…

这份“插件英雄榜Top20”才是Chrome的正确打开方式!

作者 | zhaoolee整理 | Jane出品 | AI科技大本营&#xff08;公众号id&#xff1a;rgznai100&#xff09;前言”一入开源深似海”&#xff01;给大家推荐优秀的开源项目、实用工具已经成为 AI科技大本营的固定节目。“我待开源如初恋”&#xff0c;逛淘宝&#xff0c;点收藏&am…

【Qt】Qt样式表总结(二):冲突和命名空间

Qt样式表总结&#xff08;一&#xff09;&#xff1a;选择器 解决冲突 针对同一个控件的相同属性&#xff0c;使用多种选择器时&#xff0c;会出现冲突。如&#xff1a; QPushButton#okButton { color: gray } QPushButton { color: red } 解决冲突的规则是&#xff1a;更…

编程自动化,未来机器人将超越人类?

近年&#xff0c;创业者陈曦正专注于一个项目——编程自动化。即机器人可以自己编程&#xff0c;这到底意味着什么呢&#xff1f; 在美国科幻大片《终结者2》中&#xff0c;20世纪末的1997年7月3日&#xff0c;人类研制的全球高级计算机控制系统“天网”全面失控&#xff0c;机…

Repeater 嵌套 Repeater

作为一个刚入行的IT小鸟&#xff0c;每天学习&#xff0c;是必须的&#xff01; 光自学肯定是不够的&#xff01;由于本人IQ比较低&#xff0c;经常一个小问题都会想不明白。 还好有媳妇儿的帮助&#xff0c;才把这个功能给实现了。 现在就在这里总结下&#xff0c;以示敬意。o…

【Qt】Qt样式表总结(三):QObject 属性

【Qt】Qt样式表总结(一):选择器 【Qt】Qt样式表总结(二):冲突和命名空间 QObject 属性 可以使用 qproperty < 属性名称 > 语法,设置任何可以Q_PROPERTY的控件 MyLabel { qproperty-pixmap: url(pixmap.png); } MyGroupBox { qproperty-titleColor: rgb(100, 2…

CVPR2019 | 斯坦福学者提出GIoU,目标检测任务的新Loss

作者 | Slumbers&#xff0c;毕业于中山大学&#xff0c;深度学习工程师&#xff0c;主要方向是目标检测&#xff0c;语义分割&#xff0c;GAN责编 | Jane本文是对 CVPR2019 论文《Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression》的解…

ASP.NET页面之间传递值的几种方式

页面传值是学习asp.net初期都会面临的一个问题&#xff0c;总的来说有页面传值、存储对象传值、ajax、类、model、表单等。但是一般来说&#xff0c;常用的较简单有QueryString&#xff0c;Session&#xff0c;Cookies&#xff0c;Application&#xff0c;Server.Transfer。 一…