
CïŒããã°ã©ãã³ã°èšèªãå匷ãããšãèšèªèªäœãšãã®ã©ã³ã¿ã€ã ã®äž¡æ¹ã®æ©èœã«åºããããŸããããã®äžéšã¯ãããã°ãçãåã§åºãç¥ãããŠããŸããã æ£çŽã«èšã£ãŠä»ãŸã§ãã£ãããšã®ãªãããšãç¹°ãè¿ãããã«ãæ¯æ¥åœŒã®è²¯éç®±ã«éããŠãå ±æãããšããã¢ã€ãã¢ãåŸãŸããã
ãããã®æ³šæäºé ã¯ãã³ãŒããããçŸãããããéããããä¿¡é Œã§ãããã®ã«ãããã®ã§ã¯ãããŸãããããã«ã¯Steve McConnellãããŸãã ãããã圌ãã¯ééããªãããªãã®èãæ¹ãšç解ã«è²¢ç®ããŸãã
以äžã®ããã€ãã¯åçŽãããããã«èŠããŸãããå¥ã®ãã®ã¯éã«é£ãããå¿ èŠã§ã¯ãããŸããããããã¯ãããŸããã
ã ãããç§ãã¡ã¯å§ããŸãïŒ
1ïŒåçã¡ã¢ãªå ã®ãªããžã§ã¯ããšã€ã³ã¹ã¿ã³ã¹ã®å Žæ
ãªããžã§ã¯ãã«ã¯ãéçãã£ãŒã«ããšãã¹ãŠã®ã¡ãœãããå«ãŸããŸãã ã€ã³ã¹ã¿ã³ã¹ã«ã¯ãééçãã£ãŒã«ãã®ã¿ãå«ãŸããŸãã ããã¯ãã¡ãœãããåã€ã³ã¹ã¿ã³ã¹ã§è€è£œããããFlyweightãã¿ãŒã³ãããã§äœ¿çšãããããšãæå³ããŸãã
2ïŒã¡ãœããã«ãã©ã¡ãŒã¿ãŒãæž¡ã
æ§é äœã¯ãã®ã³ããŒãã¡ãœããã«æž¡ããã¯ã©ã¹ã¯ãã®åç §ã®ã³ããŒãæž¡ããŸãã ããããREFããŒã¯ãŒãã䜿çšãããšãæ§é äœã¯ããèªäœãžã®ãã€ã³ã¿ãŒãæž¡ããã¯ã©ã¹ã¯å ã®ãªã³ã¯ãæž¡ããŸãã
REF . 1) , . static void Main( string[] args ) { StringBuilder sb = new StringBuilder(); sb.Append("Hello "); AppendHello(sb); Console.WriteLine(sb.ToString()); } private static void AppendHello(StringBuilder sb) { sb.Append(" World!"); sb = null; } 2) System.NullReferenceException null. static void Main( string[] args ) { StringBuilder sb = new StringBuilder(); sb.Append("Hello "); AppendHello(ref sb); Console.WriteLine(sb.ToString()); } private static void AppendHello(ref StringBuilder sb) { sb.Append(" World!"); sb = null; }
3ïŒå®è¡åã«ã³ãŒããæºåãã
CLRã«ã¯CERãããã¯ããããããã¯JITã«ãå®è¡åã«ã³ãŒããæºåããã®ã§ãå¿ èŠãªãšãã«ãã¹ãŠãæå ã«ãããããšãäŒããŸãã ãããè¡ãã«ã¯ãSystem.Runtime.CompilerServicesããã³RuntimeHelpers.PrepareConstrainedRegionsåå空éãæ¥ç¶ããŸãã
4ïŒæ£èŠè¡šçŸ
Regexã¯Compiledãªãã·ã§ã³ã§äœæã§ããŸã-ããã«ãããILã³ãŒãã§åŒãçæãããŸãã éåžžããã¯ããã«é«éã§ãããæåã®èµ·åã¯é ããªããŸãã
5ïŒé å
ILã®1次å é åã¯ãã¯ãã«ã§è¡šãããå€æ¬¡å é åãããé«éã«åäœããŸãã 1次å é åã®é åã¯ãã¯ãã«ã䜿çšããŸãã
6ïŒã³ã¬ã¯ã·ã§ã³
ICollectionããã«ã¹ã¿ã ã³ã¬ã¯ã·ã§ã³ãç¶æ¿ããããšããå§ãããŸããIEnumerableã®å®è£ ã¯ç¡æã§ãã ããããã€ã³ããã¯ã¹ã¯ãããŸããïŒéåžžã«å人çãªïŒã
7ïŒåºç¯ãªæ¹æ³
æ¡åŒµã¡ãœããã®ååãåã¡ãœããã®ååãšç«¶åããå Žåãæ¡åŒµã¡ãœããã®å®å šãªååã䜿çšã§ããåãåŒæ°ãšããŠæž¡ãããšãã§ããŸãã
StaticClass.ExtesionMethod( type );
8ïŒLINQ
LINQé 延èªã¿èŸŒã¿-éžæãå ŽæãååŸãã¹ããããªã©
LINQ eager loadingïŒãªã¯ãšã¹ãã¯ããã«å®è¡ãããŸãïŒ-ã«ãŠã³ããå¹³åãæå°ãæ倧ãToListãªã© ïŒãã ããã³ã¬ã¯ã·ã§ã³ãç¡éã®å Žåããªã¯ãšã¹ãã¯çµäºããŸãããïŒ
9ïŒåæãããã¯
æ§é åãšããªããã£ãïŒbyteãintãlong ...ïŒã«ã¯åæãããã¯ããããŸãããåæãããã¯ã¯ããªã³ã¯ãšãšãã«ãããŒãžããŒãå ã®ãªããžã§ã¯ãã«ååšããŸãã ãããã£ãŠãMonitorãïŒïŒãŸãã¯LockïŒïŒæ§æã¯æ©èœããŸããã
10ïŒã€ã³ã¿ãŒãã§ãŒã¹
CïŒã§ããã®ã¡ãœãããå®çŸ©ãããŠããã€ã³ã¿ãŒãã§ã€ã¹ã®ååïŒIDisposable.DisposeïŒãã¡ãœããåã®åã«ç€ºãããŠããå Žåãã€ã³ã¿ãŒãã§ã€ã¹ã¡ãœããã®æ瀺çãªå®è£ ïŒæ瀺çãªã€ã³ã¿ãŒãã§ã€ã¹ã¡ãœããå®è£ ãEIMIïŒãäœæããŸãã CïŒã§ã€ã³ã¿ãŒãã§ã€ã¹ã¡ãœãããæ瀺çã«å®è£ ããå Žåãã¢ã¯ã»ã¹ã¬ãã«ïŒãªãŒãã³ãŸãã¯ã¯ããŒãºïŒãæå®ããããšã¯ã§ããŸããã ãã ããã³ã³ãã€ã©ã¯ã¡ãœããã®ã¡ã¿ããŒã¿ãäœæãããšãã«ããã©ã€ããŒãã¢ã¯ã»ã¹ã¬ãã«ãå²ãåœãŠãŸããããã«ãããã€ã³ã¿ãŒãã§ã€ã¹ã¡ãœãããåŒã³åºãã ãã§ãã³ãŒããã¯ã©ã¹ã€ã³ã¹ã¿ã³ã¹ã䜿çšã§ããªããªããŸãã ã€ã³ã¿ãŒãã§ã€ã¹ã¡ãœãããåŒã³åºãå¯äžã®æ¹æ³ã¯ããã®ã€ã³ã¿ãŒãã§ã€ã¹ã¿ã€ãã®å€æ°ãä»ããŠã¢ã¯ã»ã¹ããããšã§ãã
EIMIã¯äžå¯æ¬ ã§ãïŒããšãã°ãåãååãšçœ²åãæã€2ã€ã®ã€ã³ã¿ãŒãã§ã€ã¹ã¡ãœãããå®è£ ããå ŽåïŒã
11ïŒCïŒã§ã¯ãããŸããããILã¯ãµããŒããããŠããŸã
ã€ã³ã¿ãŒãã§ã€ã¹ã®éçãã£ãŒã«ããæ»ãå€ã®ã¿ãç°ãªãã¡ãœãããªã©ã
12ïŒã·ãªã¢ã«å
ãªããžã§ã¯ãã®ã°ã©ããã·ãªã¢ã«åããå Žåãã·ãªã¢ã«åã§ããã¿ã€ããšã§ããªãã¿ã€ãããããŸãã ããã©ãŒãã³ã¹äžã®çç±ãããæžåŒèšå®ã¢ãžã¥ãŒã«ã¯ãã·ãªã¢ã«åã®åã«ãã¹ãŠã®ãªããžã§ã¯ãã«å¯ŸããŠãã®æäœã®å¯èœæ§ããã§ãã¯ããŸããã ããã¯ãSerializationExceptionãçºçããåã«ãäžéšã®ãªããžã§ã¯ããã¹ããªãŒã ã«ã·ãªã¢ã«åããããšãã«ç¶æ³ãçºçããå¯èœæ§ãããããšãæå³ããŸãã çµæãšããŠãç ŽæããããŒã¿ã¯I / Oã¹ããªãŒã ã«ãããŸãã ããã¯ãããšãã°ãMemoryStreamã§æåã«ãªããžã§ã¯ããã·ãªã¢ã«åããããšã§åé¿ã§ããŸãã
CïŒã§ã¯ã[Serializable]å±æ§ã§ããŒã¯ãããåã®å éšã§ã¯ãèªåçã«å®è£ ãããããããã£ãå®çŸ©ããªãã§ãã ããã å®éã«ã¯ãã³ã³ãã€ã©ã«ãã£ãŠçæããããã£ãŒã«ãåã¯ãåŸç¶ã®åã³ã³ãã€ã«åŸã«å€æŽãããå¯èœæ§ããããããåã€ã³ã¹ã¿ã³ã¹ããã·ãªã¢ã©ã€ãºã§ããªããªããŸãã
13ïŒå®æ°
å®æ°ã¯ã¢ã»ã³ããªã¡ã¿ããŒã¿ã«é 眮ããããããå€æŽããã£ãå Žåã¯ãããã䜿çšããŠãã¹ãŠã®ã¢ã»ã³ããªãåã³ã³ãã€ã«ããå¿ èŠããããŸãã ãªããªã å®æ°ãæã€DLLã¯ããŒããããªãå ŽåããããŸãã
ã³ã³ã¹ãã©ã¯ã¿ãŒã§éçãªèªã¿åãå°çšã®èšå®å€ã䜿çšããããšããå§ãããŸããããã䜿çšããŠã¢ã»ã³ããªã«åžžã«ããŒããããå®éã®å€ãè¿ããŸãã
14ïŒä»£è¡šè
GetInvocationList-ããªã²ãŒãã®ãã§ãŒã³ãè¿ããŸããæåŸã®åŒã³åºãã ãã§ãªããanyãåŒã³åºããŠäŸå€ããã£ãããããã¹ãŠã®æ»ãå€ãååŸã§ããŸãã
15ïŒæååã®æ¯èŒ
Microsoft Windowsã§ã¯ã倧æåã®æååæ¯èŒãæé©åãããŠããŸãã *å®éãStringComparison.OrdinalIgnoreCaseã¯Charã倧æåã«å€æããŸãã ToUpperInvariantã string.compareïŒïŒã䜿çšããŸãã Windowsã¯ããã©ã«ãã§UTF-16ãšã³ã³ãŒãã䜿çšããŸãã
16ïŒè€æ°è¡ã®æé©å
ã¢ããªã±ãŒã·ã§ã³ã§æååã倧æåãšå°æåãåºå¥ããŠæ¯èŒããããšãå€ãå ŽåããŸãã¯ã¢ããªã±ãŒã·ã§ã³ã«å€ãã®åäžã®æååãªããžã§ã¯ãã衚瀺ãããããšãäºæ³ãããå Žåã¯ãããã©ãŒãã³ã¹ãåäžãããããã«ãCLRã§ãµããŒããããæååæå¶ã¡ã«ããºã ã䜿çšããå¿ èŠããããŸãã
åæåæã«ãCLRã¯ããŒãæååã§å€ã管çããŒãå ã®æååãªããžã§ã¯ããžã®åç §ã§ããå éšããã·ã¥ããŒãã«ãäœæããŸãã
17ïŒå®å šãªã²ã
SecureStringãªããžã§ã¯ããäœæãããšãããã®ã³ãŒãã¯ãæåã®é åãå«ãã¢ã³ãããŒãžã¡ã¢ãªã®ãããã¯ãå²ãåœãŠãŸãã ã¬ããŒãžã³ã¬ã¯ã¿ãŒã¯ããã®ã¢ã³ãããŒãžã¡ã¢ãªã«ã€ããŠäœãç¥ããŸããã ãã®ã¡ã¢ãªã¯æåã§ã¯ãªã¢ããå¿ èŠããããŸãã
18ïŒã»ãã¥ãªãã£
ãããŒãžã¢ã»ã³ããªã¯ãåžžã«DEPãšASLRã䜿çšããŸãã
19ïŒã¡ãœããèšèš
ã¡ãœãããã©ã¡ãŒã¿ã®åã宣èšãããšãã¯ãåºæ¬ã¯ã©ã¹ãžã®ã€ã³ã¿ãŒãã§ã€ã¹ãåªå ããŠããæå°ãåãæå®ããå¿ èŠããããŸãã ããšãã°ãäžé£ã®èŠçŽ ã§æ©èœããã¡ãœãããäœæããå ŽåãIEnumerableã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŠã¡ãœãããã©ã¡ãŒã¿ãŒã宣èšããããšããå§ãããŸãã
public void ManipulateItems<T>(IEnumerable<T> collection) { ... }
åæã«ãã¡ãœããã«ãã£ãŠè¿ããããªããžã§ã¯ãã®ã¿ã€ãã宣èšããå©çšå¯èœãªãªãã·ã§ã³ã®äžã§æã匷åãªãã®ãéžæããããšãæãŸããã§ãïŒç¹å®ã®ã¿ã€ãã«å¶éãããªãããã«ããŠãã ããïŒã ããšãã°ãStreamã§ã¯ãªãFileStreamãªããžã§ã¯ããè¿ãã¡ãœããã宣èšããããšããå§ãããŸãã
20ïŒè»ã®ç¹æ§ã«ã€ããŠããäžåºŠ
AIPã®èªåçã«å®è£ ãããããããã£ã䜿çšããªãããšããå§ãããŸãïŒèè ã®æèŠãã©ã¡ããæšæž¬ãããïŒã
aïŒããã©ã«ãå€ã¯ãã³ã³ã¹ãã©ã¯ã¿ãŒã§ã®ã¿èšå®ã§ããŸãã ïŒRoslyn CïŒ6ã§å€æŽïŒ;
bïŒã·ãªã¢ã«åã®åé¡ïŒæ®µèœ12ïŒã
cïŒãã¬ãŒã¯ãã€ã³ããèšå®ã§ããŸããã
21ïŒèšå®ãã¡ã€ã«
aïŒä»»æã®ãã€ããª.NETã³ãŒããå€éšXMLæ§æãã¡ã€ã«ã«é¢é£ä»ããããšãã§ããŸãã ãã®ãã¡ã€ã«ã¯åããã£ã¬ã¯ããªã«ãããæ«å°Ÿã«.CONFIGãšããåèªãè¿œå ãããåãååã§ãã
bïŒãœãªã¥ãŒã·ã§ã³ããã€ããªåœ¢åŒã§ã®ã¿æäŸããå Žåãããã¥ã¡ã³ãåã³ã¡ã³ãã¯ã³ã³ãã€ã«äžã«XMLãã¡ã€ã«ã«ã³ã³ãã€ã«ã§ããããããã®ç¶æ³ã§ããåªãããã³ãããŠãŒã¶ãŒã«æäŸã§ããŸãã ãããè¡ãã«ã¯ãçµæã®XMLãã¡ã€ã«ããã€ããªãšåããã£ã¬ã¯ããªã«é 眮ããã ãã§ãVisual Studio .NETã¯IntelliSenseããã³ããã«ã³ã¡ã³ããèªåçã«è¡šç€ºããŸãã
22ïŒäŸå€
CLRã¯ãäŸå€ã®éå§ç¹ããªã»ããããŸãã
try {} catch (Exception e) { throw e; }
CLRã¯ãäŸå€ã®éå§ç¹ã«é¢ããæ å ±ãå€æŽããŸããã
try {} catch (Exception e) { throw; }
CLRããã³ãã©ãŒã®æ€çŽ¢ãéå§ããåã«ãAppDomainã¯ã©ã¹ã®FirstChanceExceptionã€ãã³ããçºçãããäŸå€ã«é¢ããæ å ±ãåãåãããšãã§ããŸãã
äŸå€ã¯ãã£ããåäœããŸã ã«ãŒãã«ã¢ãŒããžã®ç§»è¡ããããŸãã
23ïŒISããã³AS
IS-ãã®ã³ãŒãã§ã¯ãCLRã¯ãªããžã§ã¯ãã2åãã§ãã¯ããŸãã
if ( obj is Person ) { Person p = (Person) obj; }
AS-ãã®å ŽåãCLRã¯objã®Personåãšã®äºææ§ã1åã ããã§ãã¯ããŸãã
Person p1 = obj as Person; if ( p1 != null ) { ... }
24ïŒå®è¡ããåã«ååãªã¡ã¢ãªããããã©ããã確èªããŸã
MemoryFailPointã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæãããšãã¢ã¯ã·ã§ã³ãéå§ããåããŸãã¯äŸå€ãã¹ããŒããåã«ãååãªã¡ã¢ãªããããã©ããã確èªãããŸãã ãã ããç©çã¡ã¢ãªã¯ãŸã å²ãåœãŠãããŠããªãããšã«æ³šæããŠãã ããããã®ã¯ã©ã¹ã¯ãã¢ã«ãŽãªãºã ãå¿ èŠãªã¡ã¢ãªãåãåãããšãä¿èšŒã§ããŸããã ãããããã®äœ¿çšã¯ééããªãã¢ããªã±ãŒã·ã§ã³ã®ä¿¡é Œæ§ãé«ããã®ã«åœ¹ç«ã¡ãŸãã
25ïŒNullã«ã€ããŠ
nulläºæã®Int32ã䜿çšããã«ã¯ã次ã®ããã«èšè¿°ã§ããŸãã
Nullable<Int32> x = null; Int32? x = null;
nulläºæå€ã®çµåæŒç®åã¯?? ïŒå·Šã®ãªãã©ã³ããnullã®å ŽåãæŒç®åã¯æ¬¡ã®ãªãã©ã³ãã«é²ã¿ãŸãïŒã2ã€ã®åçã®åŒãæ€èšããŸãã
1ïŒ
string temp = GetFileName(); string fileName = ( temp != null ) ? temp : "Untitled";
2ïŒ
string fileName = GetFileName() ?? "Untitled";
26ïŒã¿ã€ããŒ
FCLã©ã€ãã©ãªã«ã¯ãããŸããŸãªã¿ã€ããŒãå«ãŸããŠããŸãã
1ïŒSystem.Threadingã®ã¿ã€ããŒ-ããŒã«ã¹ã¬ããã§ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ãå®è¡ããã®ã«é©ããŠããŸãã
2ïŒSystem.Windows.Formsã®ã¿ã€ããŒ-ã¿ã€ããŒã¯åŒã³åºãã¹ã¬ããã«é¢é£ä»ããããŠããŸããããã«ããã䞊ååŒã³åºããé²æ¢ãããŸãã
3ïŒSystem.Windows.Threadingã®DispatcherTimerã -2çªç®ãšåçã§ãããSilverlightããã³WPFã¢ããªã±ãŒã·ã§ã³çšã
4ïŒSystem.Timersã®ã¿ã€ããŒã -å®éãæåã®ã·ã§ã«ã§ãããããJeffrey Richterã¯ããã䜿çšããããšãæšå¥šããŠããŸããã
27ïŒtypeããã³typeof
åã®Typeã€ã³ã¹ã¿ã³ã¹ãååŸããã«ã¯ãType.GetTypeã¡ãœããã®ä»£ããã«typeofæäœã䜿çšãããŸãã ã³ã³ãã€ã«æã«åãããã£ãŠããå Žåãtypeofæäœã¯å®è¡æã«ã¡ãœãããå®è¡ããã®ã§ã¯ãªããããã«ã¡ãœãããæ€çŽ¢ããŸãã
28ïŒãããã䜿çšãã
ã³ãŒãã®éãæžãããŠããæ確ã«ããããã«ïŒ 次ã®ããã«usingãã£ã¬ã¯ãã£ãã䜿çšã§ããŸãã
䜿çšDateTimeList = System.Collections.Generic.List <System.DateTime>;
29ïŒããªããã»ããµãã£ã¬ã¯ãã£ã
aïŒ#IF DEBUGããã³#ENDIF-DEBUGã¢ãŒãã§ã®ã¿ã³ã³ãã€ã«ãããã³ãŒããããã¯ã瀺ãããã«äœ¿çšãããŸãã
bïŒ#DEFINE XXX; #IFïŒDEBUG && XXXïŒ-ã¢ã»ã³ããªçªå·ãXXXããæ¡ä»¶ã«è¿œå ã§ããŸãã
cïŒïŒDEBUG == RELEASEïŒå¿µã®ããïŒã
dïŒ#LINE 111-ãšã©ãŒãŠã£ã³ããŠã«111è¡ç®ã衚瀺ãããŸãã
eïŒ#LINE HIDDEN-ãããã¬ãŒããè¡ãé衚瀺ã«ããŸãã
fïŒ#WARNING XXX; #ERROR YYY-XXX-èŠåãYYY-ãšã©ãŒãæå³ããŸãã
30ïŒä»»æ*å€ã
å ±åæ£-çŽæ¥é ã®å€æãããŒã¯ãŒãOUTã
string[] strings = new string[3]; object[] objects = strings; interface IMyEnumerator<out T> { T GetItem( int index ); } T --> R IOperation<T> --> IOperation<R>
ååæ£-éé ã®å€æãããŒã¯ãŒãINã
interface IMyCollection<in T> { void AddItem( T item ); } R --> T IOperation<T> --> IOperation<R>
äžå€æ§-æé»çãªåå€æã¯èš±å¯ãããŠããŸããã
ããã©ã«ãã§ã¯ããžã§ããªãã¯åã¯äžå€ã§ãã ãŸã äžè¬åãããã¯ã©ã¹ã¯ãªãŒãã³ãšåŒã°ããå®è¡æã«ã¯ãããšãã°ç¹å®ã®ã¿ã€ãã®ãintãããstringãã«ãã£ãŠã¯ããŒãºãããŸãã ãããŠããããã¯ç°ãªãã¿ã€ãã§ããããããã®éçãã£ãŒã«ããç°ãªããŸãã
31ïŒæ¡åŒµã¡ãœãã
public static class StringBuilderExtensions { public static Int32 IndexOf ( this StringBuilder sb, Char char) { ... } }
ã€ã³ã¹ã¿ã³ã¹ã¡ãœããæ§æã«ãã£ãŠåŒã³åºãããéçã¡ãœãããå®çŸ©ã§ããŸãã ããšãã°ãStringBuilderã«å¯ŸããŠç¬èªã®IndexOfã¡ãœãããå®çŸ©ã§ããŸãã ãŸããã³ã³ãã€ã©ãŒã¯StringBuilderã¯ã©ã¹ãŸãã¯ãã®ãã¹ãŠã®åºæ¬ã¯ã©ã¹ã調ã¹ãŠãå¿ èŠãªãã©ã¡ãŒã¿ãŒãæã€IndexOfã¡ãœãããååšãããã©ããã確èªããŸããèŠã€ãããªãå Žåã¯ãç¹å®ã®IndexOfã¡ãœãããæã€éçã¯ã©ã¹ãæ¢ããŸãã
ãããŠãããã¯.Netã®Visitorãã¿ãŒã³ã®å®è£ ã§ãã
32ïŒå®è¡ã³ã³ããã¹ã
åã¹ã¬ããã«ã¯ç¹å®ã®å®è¡ã³ã³ããã¹ãããããŸãã ããã«ã¯ãã»ãã¥ãªãã£èšå®ããã¹ããã©ã¡ãŒã¿ãŒãããã³è«çåŒã³åºãã³ã³ããã¹ãããŒã¿ãå«ãŸããŸãã ããã©ã«ãã§ã¯ãCLRã¯æåã®ã¹ã¬ãããããã¹ãŠã®è£å©ã¹ã¬ããã«èªåçã«ã³ããŒããŸãã ããã«ãããåãã»ãã¥ãªãã£èšå®ãä¿èšŒãããŸãããããã©ãŒãã³ã¹ãäœäžããŸãã ãã®ããã»ã¹ãå¶åŸ¡ããã«ã¯ãExecutionContextã¯ã©ã¹ã䜿çšããŸãã
33ïŒæ®çºæ§
JIT-ã³ã³ãã€ã©ã¯ããã®ããŒã¯ãŒãã§ããŒã¯ããããã£ãŒã«ããžã®ã¢ã¯ã»ã¹ããæ®çºæ§ã®èªã¿åããŸãã¯æžã蟌ã¿ã¢ãŒãã§çºçããããšãä¿èšŒããŸãã CïŒã³ã³ãã€ã©ãŒãšJITã³ã³ãã€ã©ãŒããã£ãŒã«ãã®å 容ãããã»ããµãŒã»ã¬ãžã¹ã¿ãŒã«ãã£ãã·ã¥ããããšãçŠæ¢ããŸããããã«ããããã¹ãŠã®èªã¿åãããã³æžã蟌ã¿æäœäžã«ãã¡ã¢ãªãŒã§æäœãçŽæ¥å®è¡ãããããšãä¿èšŒãããŸãã
34ïŒäžŠåã¹ã¬ããåŠçã®ã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹
ConcurrentQueue-FIFOã¢ã«ãŽãªãºã ã«åŸã£ãŠåŠçèŠçŽ ã
ConcurrentStack-LIFOã¢ã«ãŽãªãºã ã䜿çšããåŠçèŠçŽ ã
ConcurrentBag-éè€ãèš±å¯ãããœãŒããããŠããªãèŠçŽ ã®ã»ããã
ConcurrentDictionary <TKeyãTValue>-ããŒãšå€ã®ãã¢ã®ãœãŒããããŠããªãã»ããã
35ïŒã¹ããªãŒã
ãŠãŒã¶ãŒã¢ãŒãã®èšèšïŒ
aïŒæ®çºæ§æ§é -ã¢ãããã¯ãªèªã¿åããŸãã¯æžã蟌ã¿æäœã
VolatileWriteãVolatileReadãMemoryBarrierã
bïŒã€ã³ã¿ãŒããã¯æ§é -ã¢ãããã¯ãªèªã¿åããŸãã¯æžã蟌ã¿æäœã
System.Threading.InterlockedïŒã€ã³ã¿ãŒããã¯ïŒããã³System.Threading.SpinLockïŒã«ãŒãã§ããã¯ïŒã
ã©ã¡ãã®æ§æã§ãããªã³ã¯ïŒã¡ã¢ãªå ã®ã¢ãã¬ã¹ïŒãå€æ°ã«æž¡ãïŒæ§é ãåŒã³åºãïŒå¿ èŠããããŸãã
ã«ãŒãã«ã¢ãŒãã®æ§æïŒ
ãŠãŒã¶ãŒã¢ãŒãã®æ§ç¯ãããçŽ80åé ããªããŸãããMSDNã§èª¬æãããŠããå€ãã®å©ç¹ããããŸãïŒå€ãã®ããã¹ãïŒã
ã¯ã©ã¹éå±€ïŒ
WaitHandle EventWaitHandle AutoResetEvent ManualResetEvent Semaphore Mutex
36ïŒã¯ã©ã¹ãã£ãŒã«ã
ãã£ãŒã«ããæ瀺çã«åæåãããããã©ã«ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒã§ãããè¡ããåŒæ°ãåãã³ã³ã¹ãã©ã¯ã¿ãŒã«å¯ŸããŠthisïŒïŒããŒã¯ãŒããšãšãã«äœ¿çšããŸãã ããã«ãããã³ã³ãã€ã©ãçæããILã³ãŒããå°ãªããªããŸãã åæåã¯ããããã®ã³ã³ã¹ãã©ã¯ã¿ãŒã§1åçºçããŸãïŒãã¹ãŠã®ã³ã³ã¹ãã©ã¯ã¿ãŒãåãå€ãã³ããŒãæã€ããã§ã¯ãããŸããïŒã
37ïŒããã°ã©ã ã®ã³ããŒã1ã€ã ãå®è¡ãã
public static void Main () { bool IsExist; using ( new Semaphore ( 0, 1, "MyAppUniqueString", out IsExist ) ) { if ( IsExist ) { /* , . */ } else { /* , , Main, . */ } }}
38ïŒã¬ããŒãžã³ã¬ã¯ã·ã§ã³
CLRã¯2ã€ã®ã¢ãŒããå®è£ ããŸãã
1ïŒã¯ãŒã¯ã¹ããŒã·ã§ã³-ã³ã¬ã¯ã¿ãŒã¯ãä»ã®ã¢ããªã±ãŒã·ã§ã³ãããã»ããµãŒãªãœãŒã¹ã䜿çšããªããšä»®å®ããŸãã ã¢ãŒã-䞊åã¢ã»ã³ããªã®æç¡ã«ãããããã
2ïŒãµãŒããŒã³ã¬ã¯ã¿ãŒã¯ããµãŒãããŒãã£ã®ã¢ããªã±ãŒã·ã§ã³ããã·ã³äžã§å®è¡ãããŠãããããã¹ãŠã®CPUãªãœãŒã¹ãã¢ã»ã³ããªã®ããã«å®è¡ãããŠããããšãåæãšããŠããŸãïŒ ãããŒãžããŒãã¯ãããã»ããµããšã«1ã€ã®ã»ã¯ã·ã§ã³ã«åå²ãããŸãïŒãã¹ãŠã®çµæãã€ãŸããããŒãããšã«1ã€ã®ã¹ã¬ããïŒã
39ïŒãã¡ã€ãã©ã€ã¶ãŒ
åé€åã®ãªããžã§ã¯ãã®æåŸã®æ¬²æ±ã®æ©èœãæºããã40ç§ããé·ãæç¶ããããšã¯ã§ããŸãããããã§éãã§ã¯ãããŸããã ãªããžã§ã¯ããå°ãªããšã1äžä»£ã«å€æããŸãã ããã«ã¯åé€ãããŸããã
40ïŒæœèšã§ã®ã¬ããŒãžã³ã¬ã¯ã¿ã®ç£èŠãšç®¡ç
GCHandleãªããžã§ã¯ãã®éçAllocã¡ãœãããåŒã³åºãããªããžã§ã¯ããžã®åç §ãæž¡ããGCHandleTypeãå ¥åããŸãã
1ïŒåŒ±-ç£èŠããªããžã§ã¯ãã䜿çšã§ããªããªã£ãããšããããããã¡ã€ãã©ã€ã¶ãå®è¡ã§ããã
2ïŒWeakTrackResurrection-ç£èŠããªããžã§ã¯ããå©çšã§ããªããªã£ãŠããããšããããããã¡ã€ãã©ã€ã¶ãŒãå®è¡ãããå ŽåïŒååšããå ŽåïŒã
3ïŒéåžž-ã³ã³ãããŒã«ããªããžã§ã¯ããã¡ã¢ãªã«æ®ããŸãããã®ãªããžã§ã¯ããå æããã¡ã¢ãªã¯å§çž®ã§ããŸãã
4ïŒåºå®-ã³ã³ãããŒã«ããªããžã§ã¯ããã¡ã¢ãªã«æ®ããŸãããã®ãªããžã§ã¯ããå æããã¡ã¢ãªã¯å§çž®ïŒç§»åïŒã§ããŸããã
41ïŒCLR
CLRã¯ãæ¬è³ªçã«MSILåœä»€çšã®ããã»ããµã§ãã åŸæ¥ã®ããã»ããµã¯ã¬ãžã¹ã¿ãšã¹ã¿ãã¯ã䜿çšããŠãã¹ãŠã®åœä»€ãå®è¡ããŠããŸããããCLRã¯ã¹ã¿ãã¯ã®ã¿ã䜿çšããŸãã
42ïŒååž°
ã¢ããªã±ãŒã·ã§ã³ãããã«1ç§éåæ¢ãããšã©ãŒã¡ãã»ãŒãžãªãã§å®å šã«æ¶ããã®ãèŠãããšãããã°ãããã¯ã»ãŒééããªãç¡éã®ååž°ãåå ã§ããã ãåãã®ãšãããã¹ã¿ãã¯ãªãŒããŒãããŒã¯ã€ã³ã¿ãŒã»ããããã³åŠçã§ããŸããã ãªãã§ïŒ æ¬ãããã°ãèªã¿ãŸãã
43ïŒWindbgãšSOSïŒSon of StrikeïŒ
ããã»ã¹ã«ã¯äžåºŠã«ããã€ã®ãã¡ã€ã³ãååšããŸããïŒ
-3.ã·ã¹ãã ãã¡ã€ã³ãå ±æãã¡ã€ã³ãããã³ãã¡ã€ã³1ïŒçŸåšã®ã¢ããªã±ãŒã·ã§ã³ã³ãŒããæã€ãã¡ã€ã³ïŒã
å®éã«ã¯ããã€ã®ããŒãïŒäžä»£ïŒããããŸããïŒ
-0ã1ã2ãããã³ã©ãŒãžãªããžã§ã¯ãããŒãã
ã©ãŒãžãªããžã§ã¯ãããŒã-éåžžã«å€§ããªãªããžã§ã¯ãã®å Žåãããã©ã«ãã§ã¯å§çž®ããããæ§æXMLãã¡ã€ã«å ã®æ§æã«ãã£ãŠã®ã¿å§çž®ãããŸãã
ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®ã¯ã©ã€ã¢ã³ãã¢ãŒããšãµãŒããŒã¢ãŒãã®ãã1ã€ã®éãïŒæžç±ã§ã¯ãã¹ãŠã詳现ã§ãããšã¯éããã翻蚳ã®äžæ£ç¢ºããå¯èœã§ãïŒã
- åã³ã¢ã«å¯ŸããŠãç¬èªã®HEAPãäœæãããããããã«ç¬èªã®0ã1ã2äžä»£ããã³ã©ãŒãžãªããžã§ã¯ãããŒãããããŸãã
64ããããã©ãããã©ãŒã ã§2 GBãè¶ ããã¢ã¬ã€ãäœæããã
-gcAllowVeryLargeObjects enabled = "true | false"
空ãã¡ã¢ãªã¯ããããæ°ãããªããžã§ã¯ãã«å€§ããªé£ç¶ã»ã¯ã·ã§ã³ãå²ãåœãŠãããšãã§ããªãå Žåã¯ã©ãããã°ããã§ããïŒ
- ã©ãŒãžãªããžã§ã¯ãããŒãã®ã³ã³ãã¯ãã¢ãŒããæå¹ã«ããŸãã GCSettings.LargeObjectHeapCompactionMode;
䜿çšããããšã¯æšå¥šãããŸãããã¡ã¢ãªå ã®å€§ããªãªããžã§ã¯ãã移åããã®ã¯éåžžã«é«äŸ¡ã§ãã
å®è¡æã«ã¹ã¬ããã«ãŒãïŒãããããã¯ïŒãæ€åºããé床ã¯ã©ããããã§ããïŒ
-ïŒDlk
ãœãŒã¹ïŒåºåã§ã¯ãªãïŒïŒ
1ïŒJeffrey RichterããCïŒãä»ããCLRã第3ç/第4çã
2ïŒTrey Nashãããããã§ãã·ã§ãã«åãã®CïŒ2010ã¯ã©ãã·ã¥ã³ãŒã¹ãã
3ïŒJohn RobbinsããMicrosoft .NETããã³Microsoft Windowsçšã®ã¢ããªã±ãŒã·ã§ã³ã®ãããã°ãã
4ïŒAlexander ShevchukïŒMCTSãMCPDãMCTïŒããã³Oleg KulyginïŒMCTSãMCPDãMCTïŒITVDNãªãœãŒã¹ïŒhttps://www.youtube.com/user/CBSystematicsTV/videos?shelf_id=4&view=0&sort=ddïŒã
5ïŒã»ã«ã²ã€ã»ãã¬ãã§ãã Microsoftãšã³ãžãã¢ïŒhttps://www.youtube.com/watch?v=XN8V9GURs6oïŒ
ãã®ãªã¹ããåå¿è ãšçµéšè±å¯ãªCïŒããã°ã©ãã®äž¡æ¹ã«æ¥œããã§ããã ããã°å¹žãã§ãã
ãæž èŽããããšãããããŸããïŒ
*æŽæ°ããããšã©ãŒãä¿®æ£ããããã€ãã®ãã€ã³ãã«äŸãè¿œå ããŸããã
ééããèŠã€ããå Žåã¯ãå人çãªã¡ãã»ãŒãžã§ãããå ±åããŠãã ããã