16

Today I got a segmentation fault in C#.

No pointers. No unmanaged dependencies. Just managed code. Seg fault.

Uhhhh...

Comments
  • 0
    Perhaps broken memory?
  • 0
    That's... odd

    I'd suggest running memtest to ensure its not a hardware issue
  • 3
    I'd put that on my resume. I can't think of a reliable way to segfault with managed code only
  • 1
    @bad-frog "a segfault occurs when you try to access memory that has been allocated to a different process and the processor sees it."

    That is not how paging and virtual memory works. The memory a process have access to has to be requested from the kernel (see man mmap) and it becomes a virtual address range, the process has to access it with that virtual address, which should be random (ALSR), and it has nothing to do with the underlying address of the allocated pages.

    Hardware fault can mean random bit flips that change addresses. C# should raise an exception when you access an array out of range.
  • 0
    Do you use ECC RAM and have enabled ECC? If not, buy ECC RAM. This is why you don't develop on a (crappy) Laptop.
  • 2
    @happygimp0 not everyone is that rich
  • 8
    @happygimp0 Calling non-ECC memory a crappy laptop machine is the most elitist shit I've heard today lmfao
  • 0
    @happygimp0 seriously, say this to 1000 users he's probably targeting
  • 1
    @bad-frog You never wrote C# and you're just talking out of your ass right now.
    In C#:
    Everything is automatically initialized
    There is no raw array, the array you can access is bounds checked and throws exceptions
    Due to garbage collection nothing you have access to can ever be deleted
    Hardware can cause segfaults when a bit in memory is broken and fails to change value. In this case, any computational guarantees regarding the validity of values are obviously meaningless, however you won't discover a broken bit until an application writes something critical over it and crashes because nothing at or below OS level utilizes or tests every single bit of memory.
  • 1
    @homo-lorens
    looks like i was.
    i stand corrected.
    didnt realize how different C# was from C/C++
  • 1
    @bad-frog I made the same assumption when I started studying C#, but they have about as much in common as Java does with Javascript.
  • 1
    @homo-lorens
    yeah, just installed visual studio + sdk.
    it took me whole 5 minutes studying the manual to understand my error.
    strings are not null terminated. all arrays are composite objects which include an element count, used to check index vs index range.
    and you cant access the crispy stuff without flagging your code as unsafe = using pointers.
    all initialization and garbage collection is handled by code written by microsoft.

    managed code makes much more sense to me now.

    also i thought ram integrity is checked on boot.
    as for ECC, i thought the chance of it actually being usefull is astronomically low, but if thats what occurred, it would look exactly like an elusive seg error...
  • 3
    @bad-frog Once upon a time operating systems did check RAM on startup, but for a while now quick boot times are valued over safety so they only check certain parts of the file system every month or so to minimise the chance of data loss.
  • 0
    @homo-lorens
    heh, i know. my first pc was a 386DX.
    it didnt seem to take that long from what i remember. i thought it was still done today, seems to be a healthy practice.

    i will look into this matter in detail. seems pretty important to have control over that.
  • 3
    @bad-frog There's definitely nothing stopping you from putting memtest into an init script.
  • 1
    @homo-lorens
    i might just do that. i shut down/reboot my pc once a month, so it isnt like boot times are important to me.
  • 0
    @AlgoRythm You risk memory errors without ECC, which causes crashes in the best case and silent corrupt data in worst case, costing way way more than a PC with ECC. There where cheap machines with ECC last time i checked, you can get a PC with ECC for less than 300€, they are slow and second hand, but i rather prefer data integrety over performance.
  • 0
    @LotsOfCaffeine If you develop code you should be able to afford 300€ for your PC.
  • 0
    @vintprox The problem is Intel and other companies making non-ECC the standard. ECC would not cost significantly more if it would be standard. Look at RAM-prices, you don't significantly get cheaper by buying 4GiB sticks over 8GiB.

    I, as a developer, don't need more than 4 GiB in total. I would much rather have 4 GiB ECC than 8 GiB non-ECC, and ECC only needs an additional 1/8 space, not double.
  • 1
    @happygimp0 I spent a lot more on my pc than 300 bucks but I'm not gonna double that amount for the fitting motherboard and ram
    It's stupidly overpriced and I blame intel for that, but I'm not gonna waste my money on that
Add Comment