JsonSchemaResultsCollector.Create Method
Definition
Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: JsonSchemaResultsCollector.cs
Create(JsonSchemaResultsLevel, int)
Creates a JSON schema results collector from the thread-local pool with optimal memory management.
public static JsonSchemaResultsCollector Create(JsonSchemaResultsLevel level, int estimatedCapacity)
Parameters
| Name | Type | Description |
|---|---|---|
level |
JsonSchemaResultsLevel |
Controls result verbosity and collection overhead: - Basic: Failure messages only (lowest overhead) - Detailed: Detailed failure context (moderate overhead) - Verbose: All validation events (highest overhead) |
estimatedCapacity |
int |
Expected number of validation results to optimize internal buffer sizing. Accurate estimation prevents reallocations and improves performance. Use 0 for unknown capacity (defaults to 30). (optional) |
Returns
A pooled JsonSchemaResultsCollector instance ready for validation result collection. Must be disposed to return resources to the pool.
Remarks
Pooling Behavior: This method leverages thread-local pooling for optimal performance in high-throughput scenarios. The first call per thread returns a cached instance; subsequent concurrent calls create new instances. Always dispose the returned collector to ensure proper pool management. Memory Pre-allocation: - Path Buffers: (estimatedCapacity × 32 bytes) + 1024 bytes for path segments - Message Buffer: Varies by level - Basic: minimal, Verbose: (estimatedCapacity × 128 bytes) - Schema Path Buffer: Additional 4096 bytes for URI base length Performance Guidelines: - High Throughput: Use accurate capacity estimation to minimize allocations - Memory Constrained: Use lower verbosity levels and conservative capacity estimates - Debugging: Use Verbose level with generous capacity estimates for complete information
Applies To
| Product | Versions |
|---|---|
| .NET | 9, 10 |
| .NET Standard | 2.0, 2.1 |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests.
Open an issue