Created
October 21, 2025 09:54
-
-
Save bukowa/a640c2deab0fab4496f3c4f52c69761c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import random | |
| import os | |
| def memory_churn_for_debugging(): | |
| """ | |
| Allocates 2GB of string-like data, waits for a debugger to attach, | |
| then enters a maximum-speed loop to continuously and randomly modify the data. | |
| """ | |
| target_bytes = 2 * 1024 * 1024 * 1024 # 2 GB | |
| # Use a large, uniform chunk size for efficiency. 1MB per chunk. | |
| chunk_size = 1024 * 1024 | |
| num_chunks = target_bytes // chunk_size | |
| data_store = [] | |
| # ========================================================================= | |
| # PHASE 1: ALLOCATE 2GB OF MEMORY | |
| # ========================================================================= | |
| print(f"PHASE 1: Allocating {num_chunks} chunks of {chunk_size/1024**2:.0f}MB each...") | |
| try: | |
| for i in range(num_chunks): | |
| # Create a bytearray, which is a *mutable* sequence of bytes. | |
| # This is much faster for in-place modification than strings. | |
| chunk = bytearray(b'A' * chunk_size) | |
| data_store.append(chunk) | |
| # Simple progress indicator | |
| if (i + 1) % 100 == 0: | |
| print(f" Allocated {(i + 1) * chunk_size / (1024**2):.0f} MB...") | |
| except MemoryError: | |
| print("\n[ERROR] MemoryError: Could not allocate the full 2GB.") | |
| print("The system may not have enough free RAM. Try closing other applications.") | |
| sys.exit(1) | |
| print(f"\nSuccessfully allocated ~2GB of memory.") | |
| print("----------------------------------------------------------\n") | |
| # ========================================================================= | |
| # PHASE 2: PAUSE FOR DEBUGGER ATTACHMENT | |
| # ========================================================================= | |
| print(">>> PHASE 2: MEMORY IS STABLE. ATTACH YOUR DEBUGGER NOW. <<<") | |
| print(f"Process ID (PID): {os.getpid()}") | |
| input("--> Press Enter to unleash the ULTRA-FAST modification loop... ") | |
| print("\n----------------------------------------------------------") | |
| # ========================================================================= | |
| # PHASE 3: ULTRA-FAST MODIFICATION LOOP | |
| # ========================================================================= | |
| print("PHASE 3: Starting modification loop at MAXIMUM SPEED. Press Ctrl+C to stop.") | |
| try: | |
| while True: | |
| # 1. Select a random chunk of memory | |
| random_chunk = random.choice(data_store) | |
| # 2. Select a random position (index) within that chunk | |
| random_index = random.randint(0, chunk_size - 1) | |
| # 3. Generate a random byte value (0-255) | |
| random_byte_value = random.randint(0, 255) | |
| # 4. Overwrite the byte at that position. This is an extremely fast | |
| # in-place memory operation. | |
| random_chunk[random_index] = random_byte_value | |
| except KeyboardInterrupt: | |
| print("\n\nScript interrupted by user (Ctrl+C). Exiting.") | |
| except Exception as e: | |
| print(f"\nAn error occurred in the loop: {e}") | |
| if __name__ == "__main__": | |
| memory_churn_for_debugging() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment