The Programming Antihero
I was fresh out of college, still wet behind the ears, and about to enter the beta phase of my first professional game project -- a late-90s PC title. It had been an exciting rollercoaster ride, as projects often are. All the content was in and the game was looking good. There was one problem though: We were way over our memory budget.
Since most memory was taken up by models and textures, we worked with the artists to reduce the memory footprint of the game as much as possible. We scaled down images, decimated models, and compressed textures. Sometimes we did this with the support of the artists, and sometimes over their dead bodies.
We cut megabyte after megabyte, and after a few days of frantic activity, we reached a point where we felt there was nothing else we could do. Unless we cut some major content, there was no way we could free up any more memory. Exhausted, we evaluated our current memory usage. 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.
He walked out of the office and announced he had reduced the memory footprint to within budget constraints -- he was toasted as the hero of the project.
As horrified as I was back then about such a "barbaric" practice, I have to admit that I'm warming up to it. I haven't gotten into the frame of mind where I can put it to use yet, but I can see how sometimes, when you're up against the wall, having a bit of memory tucked away for a rainy day can really make a difference. Funny how time and experience changes everything.
Взето от
http://www.gamasutra.com/view/feature/4111/dirty_coding_tricks.php?print=1
-----------------------------------
Бърз превод:
Бях току що излязъл от колежа, още сукалче и на път да завърша бета фазата на първия ми професионален проект за игра – PC заглавие от края на 90-те. Беше rollercoaster, каквито често бяха проектите. Цялото съдържание беше готово и играта изглеждаше добре. Имаше обаче един проблем: бяхме над ограничението за памет.
Тъй като повечето памет беше заета от модели и текстури, работехме с художниците да намалим заетата памет от играта колкото се може повече. Намалявахме изображения, изрязвахме части от моделите и компресирахме текстури. Понякога правехме това с подкрепата на художниците, а понякога дори и през труповете им. Изрязвахме мегабайт след мегабайт, и след няколко дена обезумяла дейност достигнахме до положение в което видяхме, че не можем да направим нищо повече, освен ако не изрежем нещо важно от съдържанието. Изтощени изчислихме текущо използваната памет. Все още бяхме с мегабайт и половина над лимита.
В този момент един от най-опитните програмисти в екипа, оцелял много години на разработки в “добрите стари времена” реши да вземе нещата в свои ръце. Извика ме в офиса си и започнахме нещо, за което си представях, че ще е поредната изтощителна сесия по освобождаване на памет.
Вместо това той отвори сорс кода и ми посочи този ред:
static char buffer[1024*1024*2]; |
"Виждаш ли това?" каза той. И го изтри с едно единствено натискане на клавиш. Готово!
Вероятно е видял ужаса в очите ми и обясни, че е сложил настрана тези два мегабайта памет в началото на разработката. Знаел от опит, че винаги е невъзможно да се сведе големината на съдържанието до искания лимит на паметта и че много проекти са били близо до провал заради това. Така че като редовна практика винаги отделял настрана солиден блок от паметта, за да я освободи когато е необходимо.
Излезе от офиса си и съобщи че е намалил заетата памет в рамките на изискванията. Беше поздравен като героя на проекта.
.... Мързи ме да превеждам следващия параграф а и не знам как.