Menu

I Clamped Two Million Readings and Nothing Happened
📰

I Clamped Two Million Readings and Nothing Happened

DEV Community: dotnet·Sukhpinder Singh·18 days ago
#2XS19Qtp
#devtodotnet#devto#dev#copy#value
Reading 0:00
15s threshold

A job of mine ingests sensor readings, and one cleanup step clamps anything above 500 back down to 500. Garden-variety stuff. I wrote the loop, the tests I cared about stayed green, and the "reading over threshold" alert kept firing in staging anyway. Values above 500 were sailing straight through. The loop was right there in front of me, clearly clamping every element. Except it clamped none of them.

Here's the shape of it. The reading is a struct, because there are millions of them and I didn't want a couple million tiny objects churning through the heap:

struct Reading { public long Value ; // ...a pile of metadata fields I rarely touch

public void Clamp () { if ( Value > 500 ) Value = 500 ; } }

Enter fullscreen mode

Exit fullscreen mode

And the loop:

foreach ( var r in readings ) // readings is a List<Reading> r . Clamp ();

Enter fullscreen mode

Exit fullscreen mode

Compiles. Runs.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.