{"record":{"id":"6e66d4b622b85a7a","repo":"dotnet/machinelearning","slug":"capacity-exceeds-buffer-capacity","errorCode":null,"errorMessage":"{capacity} exceeds buffer capacity","messagePattern":"(.+?) exceeds buffer capacity","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameBuffer.cs","lineNumber":45,"sourceCode":"        }\n\n        public Span<T> Span\n        {\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\n            get => (MemoryMarshal.Cast<byte, T>(Buffer.Span)).Slice(0, Length);\n        }\n\n        public Span<T> RawSpan\n        {\n            [MethodImpl(MethodImplOptions.AggressiveInlining)]\n            get => MemoryMarshal.Cast<byte, T>(Buffer.Span);\n        }\n\n        public DataFrameBuffer(int capacity = 0)\n        {\n            if ((long)capacity > MaxCapacity)\n            {\n                throw new ArgumentException($\"{capacity} exceeds buffer capacity\", nameof(capacity));\n            }\n\n            _memory = new byte[Math.Max(capacity, MinCapacity) * Size];\n        }\n\n        internal DataFrameBuffer(ReadOnlyMemory<byte> buffer, int length)\n        {\n            _memory = new byte[buffer.Length];\n            buffer.CopyTo(_memory);\n            Length = length;\n        }\n\n        public void Append(T value)\n        {\n            EnsureCapacity(1);\n\n            RawSpan[Length] = value;\n            Length++;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameBuffer.cs#L27-L63","documentation":"DataFrameBuffer's constructor throws when the requested capacity exceeds MaxCapacity for the buffer type. Buffers are backed by contiguous memory, so an over-large capacity cannot be allocated within the allowed size.","triggerScenarios":"new DataFrameBuffer<T>(capacity) where (long)capacity > MaxCapacity (src/Microsoft.Data.Analysis/DataFrameBuffer.cs:45); e.g. passing a row count or byte-size far beyond the allowed maximum.","commonSituations":"Computing capacity from multiplied row/column counts that overflow practical limits; misconfigured batch sizes; porting code that assumed unbounded buffers.","solutions":["Reduce the requested capacity to at or below MaxCapacity","Split the data into multiple buffers/chunks","Check capacity against DataFrameBuffer<T>.MaxCapacity before constructing"],"exampleFix":"// before\nvar buf = new DataFrameBuffer<int>(int.MaxValue);\n// after\nvar buf = new DataFrameBuffer<int>(Math.Min(requested, 1_000_000));","handlingStrategy":"validation","validationCode":"if (capacity > DataFrameBuffer<T>.MaxCapacity) throw new ArgumentException(\"Requested capacity too large.\");","typeGuard":null,"tryCatchPattern":"try { var buf = new DataFrameBuffer<T>(capacity); }\ncatch (ArgumentException ex) when (ex.ParamName == \"capacity\") { /* reduce capacity or chunk data */ }","preventionTips":["Clamp computed capacities against MaxCapacity before constructing","Avoid deriving capacity from unchecked multiplications of counts","Chunk oversized datasets into multiple buffers"],"tags":["dotnet","buffer","capacity","argument-exception"],"backgroundTag":"value-out-of-range","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}