{"record":{"id":"ee609366eaa26832","repo":"microsoft/FASTER","slug":"local-memory-device-must-have-a-capacity","errorCode":null,"errorMessage":"Local memory device must have a capacity!","messagePattern":"Local memory device must have a capacity!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"cs/src/core/Device/LocalMemoryDevice.cs","lineNumber":56,"sourceCode":"        private readonly Thread[] ioProcessors;\n        private readonly int parallelism;\n        private readonly long sz_segment;\n        private readonly long latencyTicks;\n        private bool terminated;\n\n        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"capacity\">The maximum number of bytes this storage device can accommondate, or CAPACITY_UNSPECIFIED if there is no such limit </param>\n        /// <param name=\"sz_segment\">The size of each segment</param>\n        /// <param name=\"parallelism\">Number of IO processing threads</param>\n        /// <param name=\"latencyMs\">Induced callback latency in ms (for testing purposes)</param>\n        /// <param name=\"sector_size\">Sector size for device (default 64)</param>\n        /// <param name=\"fileName\">Virtual path for the device</param>\n        public unsafe LocalMemoryDevice(long capacity, long sz_segment, int parallelism, int latencyMs = 0, uint sector_size = 64, string fileName = \"/userspace/ram/storage\")\n            : base(fileName, sector_size, capacity)\n        {\n            if (capacity == Devices.CAPACITY_UNSPECIFIED) throw new Exception(\"Local memory device must have a capacity!\");\n            Debug.WriteLine(\"LocalMemoryDevice: Creating a \" + capacity + \" sized local memory device.\");\n            num_segments = (int)(capacity / sz_segment);\n            this.sz_segment = sz_segment;\n            this.latencyTicks = latencyMs * TimeSpan.TicksPerMillisecond;\n\n            ram_segment_ptrs = new byte*[num_segments];\n            orig_ram_segments = new byte[num_segments][];\n\n#if !NET5_0_OR_GREATER\n            ram_segment_handles = new GCHandle[num_segments];\n#endif\n\n            for (int i = 0; i < num_segments; i++)\n            {\n#if NET5_0_OR_GREATER\n                orig_ram_segments[i] = GC.AllocateArray<byte>((int)sz_segment, true);\n                ram_segment_ptrs[i] = (byte*)Unsafe.AsPointer(ref orig_ram_segments[i][0]);\n#else","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/Device/LocalMemoryDevice.cs#L38-L74","documentation":"A LocalMemoryDevice is an in-memory device whose total size must be known upfront to allocate its RAM segments. FASTER's Devices.CAPACITY_UNSPECIFIED sentinel is not acceptable here, so the constructor rejects it.","triggerScenarios":"Calling Devices.CreateLogDevice(path, capacity: Devices.CAPACITY_UNSPECIFIED) (or default/-1) such that LocalMemoryDevice is constructed with an unspecified capacity.","commonSituations":"Reusing storage-device configuration (capacity omitted) designed for disk devices when switching to in-memory devices; copying FASTER setup code between Kestrel/log setups where capacity was optional on emulated devices.","solutions":["Pass an explicit positive capacity, e.g. Devices.CreateLogDevice(path, capacity: 1L << 30).","Compute capacity from expected log size (segment size * number of segments).","If capacity is unknowable, use a disk/emulated device that supports unspecified capacity instead of a local memory device."],"exampleFix":"// before\nvar device = Devices.CreateLogDevice(\"/userspace/ram/storage\", capacity: Devices.CAPACITY_UNSPECIFIED);\n// after\nvar device = Devices.CreateLogDevice(\"/userspace/ram/storage\", capacity: 1L << 30); // 1 GiB","handlingStrategy":"validation","validationCode":"if (capacity <= 0 || capacity == Devices.CAPACITY_UNSPECIFIED)\n    throw new ArgumentException(\"LocalMemoryDevice requires an explicit positive capacity\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply capacity when creating in-memory devices.","Compute capacity as segmentSize * segmentCount for predictable RAM usage.","Use disk-backed devices when capacity cannot be bounded."],"tags":["csharp","device","memory-device","configuration","faster"],"backgroundTag":"missing-required-config-field","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}