7 ms·
Ok, this is just golden. We were still 1.5 MB over the memory limit! At this point one of the most experienced programmers in the team, one who had survived m
by Retric 17y ago
Ok, this is just golden.
We were still 1.5 MB over the memory limit!
At this point one of the most experienced programmers in the team, one who had survived many years of development in the "good old days," decided to take matters into his own hands. He called me into his office, and we set out upon what I imagined would be another exhausting session of freeing up memory.
Instead, he brought up a source file and pointed to this line:
static char buffer[1024 * 1024 * 2];
"See this?" he said. And then deleted it with a single keystroke. Done!
He probably saw the horror in my eyes, so he explained to me that he had put aside those two megabytes of memory early in the development cycle. He knew from experience that it was always impossible to cut content down to memory budgets, and that many projects had come close to failing because of it. So now, as a regular practice, he always put aside a nice block of memory to free up when it's really needed.
- ajg1977 17y agoYeap, this is a common and very smart thing to do. Similar tricks are to sneak in a 1-3ms delay in the main game loop so you have about 10% of your framerate reserved, and if you're not running on DVD add some sleep() calls when a file is opened so you're not fooled by the virtually non-existent seek times of the devkits HDD.
- palish 17y agoSo when the developer leaves the company...
- ajg1977 17y agoHeh, fortunately that isn't much of a concern. These are all things that a good programmer would find within 30 mins when they sit down with a profiler to eek out a few more fps or free memory. The intention is not to hide these from other engineers, but to keep a bit of performance in the bag for when needed at the end of the project. When you absolutely must hit 60fps, or fit everything into 32mb of RAM, it can be invaluable.
- mynameishere 17y agoI always figured that operating systems kept a few hundred MBs of HDD space secret to prevent catastrophes when the stupid user downloads too many "films" and hits nominal zero.
- e1ven 17y agoLinux has a format-option to reserve space for just that occasion. It defaults to 5% for root. One random link which discusses them- http://ubuntuforums.org/showthread.php?t=215177 http://ubuntuforums.org/showthread.php?t=215177
- TeHCrAzY 17y agoBut what would you do when this final few MB runs out? I beleive it wouldn't be something that would be done, it would follow a similar pattern to RAM memory, ie. Run out, you get a hard OOM error, game over.
- kragen 17y agoYou mean, what do you do to get access to these final few MB? tune2fs -m 2 /dev/sda1, that's what. (Or just run as root, like syslogd does.)
- pyre 17y agoI don't get this though. At that point, the entire team had busted their bust and had actually met their goal. This guy basically took credit for the work that the entire team had done in meeting the memory constraint. He just reserved some bogus memory so that at the last minute he could say, "Hey look! We've magically met the requirement! I'm a genius!"
- JacobAldridge 17y agoWhich is why the story is here as an example of "dirty coding tricks", and not as an example of "brilliant forward planning for coders".
- pyre 17y agoWell, when I read 'dirty coding tricks' I'm thinking 'ugly hack' not 'lousy cheater'. This wasn't some 11th hour 'patch the symptoms but not fix the underlying problem' story.
- 83457 17y agoI think the idea is to fool the team into 1) more quickly realizing their is a problem and 2) be less likely to come close to the requirement but fail. It is kind of like someone stealthily setting your clock forward 2 minutes because in their experience you have problems with punctuality.
- petercooper 17y agoThat's exactly what managers do if they have the foresight to pad a schedule.
- kgrin 17y agoThis vaguely reminds me of how some people set clocks 5 minutes ahead to make themselves think they're late. Of course, people also tend to get used to that pretty quickly and compensate accordingly, which doesn't sound like a problem here.
- mst 17y agoRight - I've found that 5 minutes I compensate for. 1-2 minutes on the other hand is little enough extra margin that I don't, but just enough to save my arse reasonably often. My business partner moves the time on his bedside clock around by 15 or 20 minutes semi-randomly every couple weeks to keep himself off balance - that didn't work for me at all but it's been doing fine for him for years now.
- ramchip 17y ago[Meta-note - I find it a bit sad that a post gets 100 points of upvote for reposting part of the article with nothing but "Ok, this is just golden." at the top.]
- petercooper 17y agoI sorta agree, but he/she took what was a wordy story and got it down to the punchline quite well.