Hacker News new | past | comments | ask | show | jobs | submit login

Great blog post. One point, though: the reason that you got a segfault with your FillChar on the array isn't because you used a dynamic array instead of static array. Dynamic arrays are just like pointers in terms of how the compiler handles them (the element count is a negative offset from the actual start of the elements, and there are other things like reference counts there also). The reason you got the segfault is because FillChar operates directly on the passed variable. In other words, your FillChar zeroed out the first 4 bytes of the pointer (not good) and then kept right on zeroing out memory that didn't belong to it (definitely not good). The reason the:


notation worked is because subscript references are equivalent to referencing the first element in the array like a variable. Therefore the FillChar started from there and properly filled the rest of the array.

Many thanks for this clarification! I have added a link to your explanation at the end of my post.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact