> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/leonardo02lobo/Memory-Monitor/llms.txt
> Use this file to discover all available pages before exploring further.

# InformationMemory

> Retrieve system memory statistics from /proc/meminfo

## Function Signature

```python theme={null}
InformationMemory() -> str | None
```

## Overview

The `InformationMemory()` function reads system memory information from `/proc/meminfo` and returns a formatted string containing key memory statistics including total memory, free memory, buffers, cached memory, and calculated used memory.

This function parses the `/proc/meminfo` file to extract essential memory metrics and presents them in a human-readable format with values in kilobytes (kB).

## Return Value

<ResponseField name="return" type="str | None">
  Returns a formatted string containing memory statistics, or `None` if the memory information cannot be read.

  The string format is:

  ```
  Memoria Total: {mem_total} kB
  Memoria Libre: {mem_free} kB
  Buffers: {buffers} kB
  Cached: {cached} kB
  Memoria Usada: {mem_used} kB
  ```
</ResponseField>

## Implementation Details

The function performs the following operations:

1. **Reads `/proc/meminfo`**: Uses `pathlib.Path` to read the contents of the system memory information file
2. **Parses memory values**: Extracts four key metrics:
   * `MemTotal`: Total usable RAM (physical RAM minus reserved bits and kernel binary code)
   * `MemFree`: Sum of LowFree + HighFree
   * `Buffers`: Relatively temporary storage for raw disk blocks
   * `Cached`: In-memory cache for files read from disk
3. **Calculates used memory**: Computes actual used memory as:
   ```python theme={null}
   mem_used = mem_total - mem_free - buffers - cached
   ```
4. **Returns formatted output**: All values are returned in kilobytes (kB)

<Note>
  The function returns `None` if the `/proc/meminfo` file cannot be read or is empty. This typically only occurs on non-Linux systems or in environments where `/proc` is not mounted.
</Note>

## Example Output

```
Memoria Total: 16384000 kB
Memoria Libre: 8192000 kB
Buffers: 512000 kB
Cached: 2048000 kB
Memoria Usada: 5632000 kB
```

## Usage Example

<CodeGroup>
  ```python Basic Usage theme={null}
  from memory_info import InformationMemory

  # Get memory statistics
  mem_stats = InformationMemory()

  if mem_stats:
      print(mem_stats)
  else:
      print("Unable to retrieve memory information")
  ```

  ```python With Error Handling theme={null}
  from memory_info import InformationMemory

  def monitor_memory():
      """Monitor system memory and handle potential errors."""
      try:
          memory_info = InformationMemory()
          
          if memory_info is None:
              raise RuntimeError("Failed to read memory information")
          
          print("Current Memory Status:")
          print(memory_info)
          
          return memory_info
      except Exception as e:
          print(f"Error monitoring memory: {e}")
          return None

  if __name__ == "__main__":
      monitor_memory()
  ```

  ```python Integration Example theme={null}
  from memory_info import InformationMemory
  import time

  def continuous_memory_monitor(interval=5):
      """Monitor memory statistics at regular intervals."""
      print("Starting memory monitor...\n")
      
      while True:
          print("="*40)
          print(f"Memory Status - {time.strftime('%Y-%m-%d %H:%M:%S')}")
          print("="*40)
          
          mem_info = InformationMemory()
          if mem_info:
              print(mem_info)
          else:
              print("Warning: Could not retrieve memory info")
          
          print()
          time.sleep(interval)

  if __name__ == "__main__":
      continuous_memory_monitor(interval=10)
  ```
</CodeGroup>

## Source Code Reference

The implementation can be found in `memory_info.py:4-32`.

## See Also

* [ListDirectory](/api/process-analyzer) - Find the process with highest memory usage
* [Quickstart Guide](/quickstart) - Get started with Memory Monitor
