CPU detection for Object Pascal
NumCPULib4Pascal is a library for detecting the number of logical and physical CPUs on the current machine in Object Pascal, compatible with both Delphi and FreePascal across multiple operating systems, released under the permissive MIT License.
- Logical CPU count -- detect the number of logical processors (hardware threads)
- Physical CPU count -- detect the number of physical cores
- Cross-platform -- Windows, Linux, macOS, Solaris, and BSD variants
- Cross-compiler -- Delphi and FreePascal
| Compiler | Minimum Version |
|---|---|
| Delphi | 2010 or later |
| FreePascal | 3.0.0 or later |
- Open package:
NumCPULib/src/Packages/Delphi/NumCPULib4PascalPackage.dpk
- Build and install the package in the IDE.
- Add
NumCPULib/srcsubfolders to your project search path if needed.
- Open package:
NumCPULib/src/Packages/FPC/NumCPULib4PascalPackage.lpk
- Build/install package in Lazarus, or add
NumCPULib/srcpaths to your FPC project.
uses
NumCPULib;
var
LLogicalCount, LPhysicalCount: Int32;
begin
// Count logical CPUs (hardware threads)
LLogicalCount := TNumCPULib.GetLogicalCPUCount();
// Count physical CPUs (cores)
LPhysicalCount := TNumCPULib.GetPhysicalCPUCount();
WriteLn(Format('Logical CPUs: %d', [LLogicalCount]));
WriteLn(Format('Physical CPUs: %d', [LPhysicalCount]));
end;Additional samples can be found in the NumCPULib.Samples folder.
Contributions are welcome. Please open an issue for bug reports or feature requests, and submit pull requests.
If you find this library useful and would like to support its continued development, tips are greatly appreciated! 🙏
This project is licensed under the MIT License.