|
| 1 | +alias:: [[Runtime]] |
| 2 | + |
| 3 | +- # Runtime |
| 4 | + - Also known as: run-time, runtime execution, execution time |
| 5 | + - The phase when a program is actually executing, after compilation |
| 6 | + - Operations and evaluations that occur while the program is running |
| 7 | + - ## Definition |
| 8 | + - The period during which a compiled program executes |
| 9 | + - The execution environment where program code runs |
| 10 | + - Dynamic behavior that cannot be determined until the program runs |
| 11 | + - ## Key Characteristics |
| 12 | + - **Dynamic Execution**: Code is executed with actual data and user input |
| 13 | + - **Runtime Environment**: The system that executes the program (virtual machine, interpreter, or native execution) |
| 14 | + - **Dynamic Behavior**: Values and control flow determined by runtime conditions |
| 15 | + - **Error Handling**: Runtime errors occur during execution |
| 16 | + - ## Runtime Operations |
| 17 | + - ### Program Execution |
| 18 | + - Instruction execution |
| 19 | + - Memory allocation and deallocation |
| 20 | + - Function calls and stack management |
| 21 | + - ### Dynamic Behavior |
| 22 | + - User input processing |
| 23 | + - Network requests |
| 24 | + - File I/O operations |
| 25 | + - Database queries |
| 26 | + - ### Runtime Checks |
| 27 | + - Array bounds checking (in some languages) |
| 28 | + - Null pointer checks |
| 29 | + - Type checks (in dynamically typed languages) |
| 30 | + - Resource availability checks |
| 31 | + - ### Memory Management |
| 32 | + - Heap allocation |
| 33 | + - Garbage collection (in managed languages) |
| 34 | + - Stack management |
| 35 | + - ## Runtime vs Compile-Time |
| 36 | + - **Runtime**: Dynamic behavior, user interaction, actual execution |
| 37 | + - **Compile-Time**: Static analysis, type checking, constant evaluation |
| 38 | + - Some languages (like Python, JavaScript) have minimal compile-time checks |
| 39 | + - ## Runtime Environments |
| 40 | + - ### Virtual Machines |
| 41 | + - JVM (Java Virtual Machine) |
| 42 | + - .NET CLR (Common Language Runtime) |
| 43 | + - Erlang BEAM |
| 44 | + - ### Interpreters |
| 45 | + - Python interpreter |
| 46 | + - JavaScript engines (V8, SpiderMonkey) |
| 47 | + - ### Native Execution |
| 48 | + - Compiled languages that run directly on hardware |
| 49 | + - Rust, C, C++, Go (when compiled to native code) |
| 50 | + - ## Runtime Errors |
| 51 | + - Errors that occur during program execution |
| 52 | + - Examples: |
| 53 | + - Null pointer exceptions |
| 54 | + - Array index out of bounds |
| 55 | + - Division by zero |
| 56 | + - File not found |
| 57 | + - Network timeouts |
| 58 | + - Contrast with compile-time errors, which prevent the program from being built |
| 59 | + - ## Language Examples |
| 60 | + - ### Dynamically Typed Languages |
| 61 | + - Python, JavaScript, Ruby: Most type checking happens at runtime |
| 62 | + - Type errors only discovered when code executes |
| 63 | + - ### Statically Typed Languages |
| 64 | + - Rust, Java, C#: Most type checking at compile-time |
| 65 | + - Runtime errors typically from logic errors or resource issues |
| 66 | + - ## Benefits and Trade-offs |
| 67 | + - **Flexibility**: Can handle dynamic data and user input |
| 68 | + - **Runtime Optimization**: Just-in-time (JIT) compilation can optimize hot paths |
| 69 | + - **Error Discovery**: Some errors only appear at runtime |
| 70 | + - **Performance Overhead**: Runtime checks add execution overhead |
| 71 | + - ## Related |
| 72 | + - [[Programming/Time/Compile]] - The compilation phase before execution |
| 73 | + - Runtime environments and virtual machines |
| 74 | + - Dynamic typing vs static typing |
0 commit comments