I want to check the number of channels and the count of RAM installed in a system. Currently dmidecode lets me do that. For example:
$ sudo dmidecode --type memory
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.3.0 present.
Handle 0x005B, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 128 GB
Error Information Handle: Not Provided
Number Of Devices: 2
Handle 0x0066, DMI type 17, 92 bytes
Memory Device
Array Handle: 0x005B
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 8 GB
Form Factor: SODIMM
Set: None
Locator: SODIMM1
Bank Locator: Channel 0 Slot 0
Type: DDR4
Type Detail: Synchronous
Speed: 2667 MT/s
Manufacturer: Crucial Technology
Serial Number: E55FEE6B
Asset Tag: 9876543210
Part Number: CB8GS2666.C8RT
Rank: 1
Configured Memory Speed: 2667 MT/s
Minimum Voltage: 1.2 V
Maximum Voltage: 1.2 V
Configured Voltage: 1.2 V
Memory Technology: DRAM
Memory Operating Mode Capability: Volatile memory
Firmware Version: Not Specified
Module Manufacturer ID: Bank 6, Hex 0x9B
Module Product ID: Unknown
Memory Subsystem Controller Manufacturer ID: Unknown
Memory Subsystem Controller Product ID: Unknown
Non-Volatile Size: None
Volatile Size: 8 GB
Cache Size: None
Logical Size: None
Handle 0x0067, DMI type 17, 92 bytes
Memory Device
Array Handle: 0x005B
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 8 GB
Form Factor: SODIMM
Set: None
Locator: SODIMM2
Bank Locator: Channel 0 Slot 0
Type: DDR4
Type Detail: Synchronous
Speed: 2667 MT/s
Manufacturer: Crucial Technology
Serial Number: E56002E0
Asset Tag: 9876543210
Part Number: CB8GS2666.C8RT
Rank: 1
Configured Memory Speed: 2667 MT/s
Minimum Voltage: 1.2 V
Maximum Voltage: 1.2 V
Configured Voltage: 1.2 V
Memory Technology: DRAM
Memory Operating Mode Capability: Volatile memory
Firmware Version: Not Specified
Module Manufacturer ID: Bank 6, Hex 0x9B
Module Product ID: Unknown
Memory Subsystem Controller Manufacturer ID: Unknown
Memory Subsystem Controller Product ID: Unknown
Non-Volatile Size: None
Volatile Size: 8 GB
Cache Size: None
Logical Size: None
I can filter the data for sure. But each dmidecode is a separate spawned process. And the user can call the function a lot of times depending on their system (please don't suggest spawning dmidecode and memoizing the value).
The main goal is to also to be fast as possible. Is there a way to get such details from within a C program assuming no linux-header is installed?