mori– Author –
-
Python樹林
[Python] Sorting Lists: Using sorted() vs. sort()
In Python, there are two main ways to sort list elements. You can use the built-in function sorted() or the list method sort(). While both achieve the same goal, they behave differently regarding the original data. This article explains ... -
Python樹林
【Python】リストを並び替える(ソート):sorted関数とsortメソッドの使い分け
Pythonでリストの要素を並び替える(ソートする)場合、主に2つの方法があります。 組み込み関数の sorted() を使う方法と、リストオブジェクトが持つ sort() メソッドを使う方法です。これらは「並び替える」という目的は同じですが、元のリストを変更す... -
C#樹林
[C#] Accelerating Data Processing with the Parallel Class
When processing large data collections, a standard foreach loop (sequential processing) uses only one CPU core. This can limit performance and lead to bottlenecks. The Parallel class, part of the C# Task Parallel Library (TPL), allows yo... -
C#樹林
【C#】Parallelクラスを用いたデータ並列処理の高速化実装
大量のデータコレクションに対して同一の処理を行う場合、foreach ループによる順次処理(シーケンシャル処理)ではCPUの単一コアしか利用できず、パフォーマンスが頭打ちになることがあります。 C#のタスク並列ライブラリ(TPL)に含まれる Parallel クラ... -
C#樹林
[C#] Safe Task Cancellation Using CancellationToken
To stop long-running asynchronous tasks (due to user actions or timeouts), the standard method is to use CancellationTokenSource and CancellationToken. This mechanism allows the caller to send a "stop command." The task detects this comm... -
C#樹林
【C#】CancellationTokenを使用したタスクの安全なキャンセル処理
長時間実行される非同期処理(Task)を、ユーザー操作やタイムアウト等の要因で途中停止(キャンセル)させるには、CancellationTokenSource と CancellationToken を使用するパターンが標準的です。 この仕組みを使うことで、呼び出し元から「停止命令」... -
C#樹林
[C#] Correct Usage of Task.Delay for Non-Blocking Waits
When pausing execution for a certain period in C#, using the traditional Thread.Sleep completely stops (blocks) the running thread. This causes UI freezes or thread pool exhaustion in web servers. In modern .NET development, the standard... -
C#樹林
【C#】スレッドをブロックしない待機処理 Task.Delay の正しい使い方
C#で一定時間処理を停止させる際、古くからある Thread.Sleep を使用すると、実行中のスレッドそのものを完全に停止(ブロック)させてしまいます。これはUIのフリーズや、Webサーバーにおけるスレッド枯渇の原因となります。 現代の.NET開発では、async/a... -
Python樹林
[C#] How to Wait for a Task Execution for a Specified Time and Handle Timeouts
When executing asynchronous operations (Task), implementing a timeout mechanism (e.g., "wait for a maximum of N seconds") is a common requirement to prevent infinite blocking. The C# Task class provides a Wait method to synchronously wai... -
C#樹林
【C#】Taskの実行を指定時間だけ待機し、タイムアウト判定を行う方法
非同期処理(Task)を実行する際、処理が無限にブロックすることを防ぐために「最大N秒まで待つ」というタイムアウト処理を実装するのは一般的な要件です。 C#の Task クラスには、処理の完了を同期的に待機する Wait メソッドが存在し、引数に制限時間を... -
C#樹林
[C#] Offloading High-CPU Synchronous Tasks with Task.Run
Executing CPU-intensive tasks (CPU-bound operations), such as image processing or complex calculations, on the main thread can cause the application's UI to freeze. In this article, I will explain an implementation pattern where such syn... -
C#樹林
【C#】CPU負荷の高い同期処理をTask.Runで非同期メソッド化する方法
画像処理や複雑な計算など、CPUリソースを大量に消費する処理(CPUバウンドな処理)をメインスレッドで実行すると、アプリケーションのUIがフリーズする原因となります。 こうした同期的な計算処理を Task.Run を用いてバックグラウンドスレッドにオフロー... -
C#樹林
[C#] Basic Implementation of Asynchronous Web Access using async/await and HttpClient
Asynchronous programming in C# allows you to write highly readable code that looks similar to synchronous code by using the async modifier and the await operator. This technology is essential for maintaining application responsiveness an... -
C#樹林
【C#】async/awaitとHttpClientを用いた非同期Webアクセスの基礎実装
C#における非同期プログラミングは、async 修飾子と await 演算子を使用することで、同期処理とほぼ変わらない可読性の高いコードで記述できます。特にネットワーク通信のようなI/O待ちが発生する処理において、アプリケーションの応答性を維持しつつシス... -
C#樹林
[C#] Implementing Background Processing with BackgroundWorker (Progress Reporting & Cancellation)
The BackgroundWorker class, available since .NET Framework 2.0, is a component for implementing event-based asynchronous processing. While the Task class and async/await syntax are mainstream today, BackgroundWorker is still used for mai... -
C#樹林
【C#】BackgroundWorkerを使用したバックグラウンド処理の実装(進捗報告・キャンセル対応)
.NET Framework 2.0から存在する BackgroundWorker クラスは、イベントベースで非同期処理を実装するためのコンポーネントです。現在では Task クラスや async/await 構文が主流ですが、Windows Formsなどの既存アプリケーションの保守や、イベント駆動型... -
C#樹林
[C#] Implementing Dynamic Type Resolution and Duck Typing with the dynamic Keyword
By using the dynamic keyword introduced in C# 4.0, you can implement dynamic behavior where type resolution happens at runtime, even though C# is a statically typed language. Usually, C# checks for the existence of methods and properties... -
C#樹林
【C#】dynamic型を活用した動的な型解決とダックタイピングの実装
C# 4.0で導入された dynamic キーワードを使用すると、静的型付け言語であるC#において、実行時に型解決を行う動的な振る舞いを実装できます。 通常、C#ではコンパイル時にメソッドやプロパティの存在確認が行われますが、dynamic型を使用することでこのチ... -
C#樹林
[C#] Simplifying Array Operations with Index and Range Structs
With the introduction of Index (the ^ operator) and Range (the .. operator) in C# 8.0, accessing elements and slicing collections (arrays, lists, spans) has become much more intuitive and safe. By utilizing these features, you can elimin... -
C#樹林
【C#】配列操作を劇的に簡潔にするIndex構造体とRange構造体の活用
C# 8.0以降で導入された Index(^演算子)と Range(..演算子)を活用することで、配列やコレクションの要素アクセス、およびスライス操作(範囲抽出)が非常に直感的かつ安全に記述できるようになりました。 従来の Length - 1 のような冗長な記述を排除... -
Python樹林
[Python] How to Merge Lists: Comparing the + Operator and extend
In Python, there are two main ways to combine multiple lists into one: using the + operator and using the extend method of a list object. While the result of "combining" is the same, their behaviors differ significantly regarding whether... -
Python樹林
【Python】リスト同士を結合・マージする方法:+演算子とextendの比較
Pythonで複数のリストを一つにまとめる際、主に + 演算子を使用する方法と、リストオブジェクトの extend メソッドを使用する方法の2通りがあります。 これらは「結合する」という結果は同じですが、**元のリストを変更するかどうか(破壊的か非破壊的か)... -
Python樹林
[Python] How to Repeatedly Generate and Initialize List Elements
In Python, using the * operator (multiplication operator) is the most concise and "Pythonic" way to create a list with specific initial values or to generate a repeating array pattern. In this article, I will explain how to efficiently e... -
Python樹林
【Python】リストの要素を繰り返し生成して初期化する方法
Pythonにおいて、特定の初期値を持つリストを作成したり、決まったパターンの繰り返し配列を生成したりする場合、* 演算子(乗算演算子)を使用するのが最もPythonらしい簡潔な記述(Pythonic)です。 for文を使用せずに、効率的にリストを展開・初期化す... -
Python樹林
[Python] Leveraging Regex Flags: A Complete Guide to Multiline and DOTALL Modes
When handling text data containing newlines in Python's re module, specifying flags is essential. In particular, if you do not correctly understand the behavior of re.MULTILINE (for line-by-line matching) and re.DOTALL (for matching acro... -
Python樹林
【Python】正規表現のフラグ活用:複数行モードとDOTALLモードの完全ガイド
Pythonの re モジュールで、改行を含むテキストデータを扱う際に必須となるのが「フラグ」の指定です。特に、行単位でのマッチングを行いたい場合の re.MULTILINE と、改行をまたいでマッチングを行いたい場合の re.DOTALL は、挙動を正しく理解していない... -
Python樹林
[Python] How to Use Greedy and Lazy Matching in Regular Expressions
In regular expressions, quantifiers such as * (0 or more) and + (1 or more) behave greedily by default. This means they try to match "the longest possible string" that satisfies the condition. On the other hand, if you want to get the "m... -
Python樹林
【Python】正規表現の「貪欲マッチ」と「最短マッチ」を使い分ける方法
正規表現において、*(0回以上)や +(1回以上)などの量指定子は、デフォルトで**貪欲(Greedy)**な挙動をとります。これは、条件を満たす限り「可能な限り長い文字列」にマッチしようとする性質です。 一方、特定の区切り文字までの「最小限の範囲」を... -
Python樹林
[Python] Getting Match Position and Content with Regex: List of Match Object Methods
When you execute re.search() or re.match() in Python's re module, a Match object is returned if the match is successful. This object holds detailed information not only about "whether it matched," but also "where it matched" and "specifi... -
Python樹林
【Python】正規表現のマッチ位置と内容を取得する:Matchオブジェクトのメソッド一覧
Pythonの re モジュールで re.search() や re.match() を実行すると、マッチが成功した場合に Match オブジェクトが返されます。このオブジェクトは、単に「マッチしたかどうか」だけでなく、「どこにマッチしたか」「具体的にどの文字列がマッチしたか」...