ขนาดสูงสุดของ List ขึ้นอยู่กับ Platform (Address Space และ/หรือ RAM) ค่าคงที่ sys.maxsize แสดงขีดจำกัดทฤษฎี
ตัวอย่าง
>> import sys >>> sys.maxsize 9223372036854775807 # 2⁶³ - 1 บน 64-bit System
ความหมายของ sys.maxsize
- ค่าบวกสูงสุดของ
Py_ssize_t(Signed Size Type ของ Python C API) - เป็นขีดจำกัดสูงสุดของ: List Length, String Length, Dict Size, และ Containers อื่นๆ
- บน 32-bit System:
2³¹ - 1 = 2,147,483,647 - บน 64-bit System:
2⁶³ - 1 = 9,223,372,036,854,775,807
ขีดจำกัดจริง (Practical Limits)
จะเจอ MemoryError ก่อนถึง sys.maxsize เสมอ
>> # พยายามสร้าง List ใหญ่เกิน RAM >>> huge_list = [0] * (10**9) # 1 Billion items MemoryError
การประมาณ Memory Usage
- List ของ int: ~28 bytes/item (64-bit CPython) → 1 ล้านรายการ ≈ 28 MB
- List ของ string/object: เพิ่มขึ้นจาก Pointer + Object Overhead
สรุป: ขีดจำกัดทฤษฎี = sys.maxsize, ขีดจำกัดจริง = RAM ที่มีอยู่