|
| 1 | +# UnmanagedStringPool Demo |
| 2 | + |
| 3 | +This directory contains a demonstration application showing practical usage of the UnmanagedStringPool library. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The demo application (`Demo.cs`) provides a hands-on example of: |
| 8 | +- Creating and managing a string pool |
| 9 | +- Allocating and freeing strings |
| 10 | +- String manipulation operations |
| 11 | +- Pool memory statistics and fragmentation monitoring |
| 12 | +- Pool growth and defragmentation |
| 13 | + |
| 14 | +## Running the Demo |
| 15 | + |
| 16 | +```bash |
| 17 | +# From the Demo directory |
| 18 | +dotnet run |
| 19 | + |
| 20 | +# Or from the project root |
| 21 | +dotnet run --project Demo/StringPoolDemo.csproj |
| 22 | +``` |
| 23 | + |
| 24 | +## Demo Features |
| 25 | + |
| 26 | +### Basic Operations |
| 27 | +- String allocation from the pool |
| 28 | +- Value semantics demonstration (struct equality) |
| 29 | +- String freeing and memory reuse |
| 30 | +- Using statement integration with disposable strings |
| 31 | + |
| 32 | +### String Manipulation |
| 33 | +- String insertion operations |
| 34 | +- Replacement and trimming |
| 35 | +- Substring extraction |
| 36 | +- Case conversion |
| 37 | + |
| 38 | +### Memory Management |
| 39 | +- Real-time fragmentation monitoring |
| 40 | +- Free space tracking |
| 41 | +- Active allocation counting |
| 42 | +- Forced defragmentation and pool growth |
| 43 | + |
| 44 | +### Performance Comparison |
| 45 | +- Timing comparisons between pooled and regular strings |
| 46 | +- Memory allocation stress testing |
| 47 | +- GC pressure demonstration |
| 48 | + |
| 49 | +## Sample Output |
| 50 | + |
| 51 | +``` |
| 52 | +Value semantics, does Hello == Hello? False |
| 53 | +Hello |
| 54 | +World |
| 55 | +This is a longer string |
| 56 | +Free space before: 3968 |
| 57 | +End block space: 3968 |
| 58 | +Active allocations: 4 |
| 59 | +Fragmentation: 0.00% |
| 60 | +... |
| 61 | +After pool growth: |
| 62 | +Free space after: 8064 |
| 63 | +End block space: 8064 |
| 64 | +Active allocations: 4 |
| 65 | +Fragmentation: 0.00% |
| 66 | +``` |
| 67 | + |
| 68 | +## Key Learning Points |
| 69 | + |
| 70 | +1. **Struct Semantics**: PooledString instances are value types with reference equality semantics |
| 71 | +2. **Memory Efficiency**: See how freed memory is immediately reused |
| 72 | +3. **Fragmentation**: Observe fragmentation patterns and defragmentation in action |
| 73 | +4. **Growth**: Watch the pool automatically grow when needed |
| 74 | +5. **Disposal**: Proper resource cleanup with using statements |
| 75 | + |
| 76 | +## Customization |
| 77 | + |
| 78 | +Modify the demo to experiment with: |
| 79 | +- Different initial pool sizes |
| 80 | +- Various string allocation patterns |
| 81 | +- Concurrent access scenarios (with proper synchronization) |
| 82 | +- Large-scale string operations |
| 83 | +- Custom fragmentation thresholds |
0 commit comments