hares-recovery

2016

Posted by Derek
Mar 08 2016

Well, we’ll see if this shows up this time with a database restore.

So, a lot has been going on. Let’s start where we left off: wrist is much improved. I can tell I’m missing some flexibility and I doubt it will ever be 100% again, but I’d confidently call it 85%. Have a couple of exercise devices - a gyroscope ball, green putty. Bothers me a little at the end of the day but not nearly as much as it used to.

Late fall / early winter, a major IT undertaking at work kicked off. It’s underway until July. Hopefully the part my team is tied up in will be winding down a little starting in April. I’ve been working from home in the evenings, cleaning up and fixing legacy code. There’s all sorts of amazing things that developers once got away with that the new system won’t allow or handles poorly. Things like the absolute gem I found yesterday, which I’ll replicate in a generic fashion:

int *number;
number = malloc(sizeof int);
number = &someOtherNumber;

What.

Okay, for those of you who don’t grok code, here’s what’s happening:

  1. We are declaring a new variable. This will be called ‘number’ and will refer to integers. The asterisk indicates that we will use this particular variable as a pointer, which means it will store a memory address that points at another value. It starts out undefined - whatever it is pointing at isn’t really valid, and it needs to be initialized.
  2. We are allocating memory, the size of an integer. This will return a memory address, which we store in our convenient new pointer made to hold memory addresses. We could store something here. But instead…
  3. We obliterate the address of the memory we just asked for, which we will never be able to find again, and replace it with the memory address (&) of another variable.

 

Since we have lost the address of the memory we just asked the system to reserve for us, we can’t tell the system we are done with it, and thus have created a tiny memory leak the size of one integer in memory. Scale this up to the structures in the real code (20 to 100 times bigger) and wrap it in a loop that runs several hundred thousand times, and there’s more than a small bit of memory lost forever (until the program exits, at least).

A lot of the issues are subversive and non-obvious, such as one I tackled today where a function would randomly corrupt the second entry in a list. It looked random until I watched how it added the new item over hundred of iterations, and discovered another bit of pointer magic badness that I won’t bore you with in extensive detail. What would generally happen is that if the function was called with exactly 100 items in a list, and it caused one more to be added, it would get into a weird state because of a leftover pointer, and fill the new entry in the list with garbage instead of the actual data that was supposed to be in there.

The nights and weekends I’m not working from home, I’ve been trying to go to the gym. This winter I hit my highest weight ever and I was starting to see some of those awesome obesity-related health issues - joint and back pain really are the gifts that keep on giving. I enrolled in a work-sponsored program called Prevent, which is sort of an online guided weight loss thing. I also picked up a local gym membership and have started trying to at the very minimum do some cardio via elliptical several times a week. I’ve changed my diet, I cut out artificial sweeteners, so on, so forth.

Mind you, I don’t feel gigantic. I do fit the medical definition of ‘obese’ but I’ve never considered myself as such when I see a lot of people far worse off than I am. Allegedly, I look slimmer than my weight. More than once, people have been surprised when I’ve told them. I’m never sure if they’re just being nice, but in any case I don’t need to look it because I feel it.

However, I am making progress, and I’m happy enough about it to plaster this infographic from my Prevent profile in public:

Screenshot 2016-03-08 23.36.38

Finally, there’s a distinct lack of something I promised months ago, and I need to correct that soon…

One Response

  1. Tsunami Sesen says:

    Woah, glad to see you finally posted something. Your still a good author, also good luck when you decide to write in the world again.