Dirty Coding Tricks

一名刚毕业的游戏开发者加入了一个90年代末期的PC游戏项目,面对超出预算的内存问题,团队成员通过压缩纹理和模型来减少内存占用。最终,一位资深程序员采用了一种非常规手段,预留了额外的内存空间,在关键时刻释放这部分内存,解决了燃眉之急。

E原文地址

里面最搞的一段

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!

我们一兆又一兆的削减,一段时间后有显著效果。。。但是也遇到了瓶颈,1.5M怎么也降不下去了,除非也主要的模型也砍掉。

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.

这个时候,team中一个很有经验的老手,他在GOOD OLD DAYS这个公司待过好多年。他决定自己接手我的事情,把我叫到办公室,我们坐下,我想着估计我们要一起好好地,深入地讨论如何释放内存了。。

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.

他看到我眼里我不满,向我解释这2M是项目开发初期,他写的代码。。以他的经验,内存削减很重要,很多项目都是因为这个失败的。所以,按照正常的做法,这块内存应该释放,需要再申请。。

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.

。。。
作者经历这么一出,估计够艹了。。
公司一般都这样,项目领导者往往是整个项目的架构者,或者一半以上的代码都是他写的。。但往往都是满足但是特定环境的,后面都需要好好改。。。

  • Noel Llopis
乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值