TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A RAM Edition of Dirty Coding Tricks

303 pointsby edgarvmover 7 years ago

10 comments

mattnewportover 7 years ago
A pretty common trick that was part of game programmer lore back in the PS2 &#x2F; Xbox era was to have a large static array hidden away in some code file somewhere. When days before shipping you couldn&#x27;t quite fit the release build in to memory this allowed a heroic programmer to miraculously &#x27;find&#x27; a few hundred extra kilobytes of memory by reducing the size of the array by just enough to fit.<p>There was a less common variant of this for finding some extra performance by reducing the iterations of a loop doing no-ops somewhere in the main game loop.
评论 #15947813 未加载
评论 #15947979 未加载
评论 #15947921 未加载
评论 #15947944 未加载
评论 #15949504 未加载
k__over 7 years ago
&quot;When finishing a level, the game would reboot the console and restart itself with a command-line argument(the name of the level to start) ... into the next level. Voila, the perfect(?) way to clear all memory between levels.&quot;<p>Well, that&#x27;s basically how most websites work, lol
评论 #15951128 未加载
评论 #15950816 未加载
russellbeattieover 7 years ago
Whenever I think, &quot;Thank goodness the limited memory days are behind us&quot;, it pops up again and again. Sure, you can buy a new iMac Pro with 128GB of RAM(!!) and smartphones regularly have 8GB available, but the increasingly popular IOT devices and smart consumer hardware (like streaming media boxes, etc.) try to limit the BOM cost and thus limit memory as much as possible. Tiny memory leaks become an issue, or random crashes from wonky media codec implementations, etc.<p>I think the skills (and hacks) that used to be useful only to game developers and OEMs are now going to be needed by a much wider audience of devs.
评论 #15947831 未加载
评论 #15947788 未加载
评论 #15948192 未加载
评论 #15952939 未加载
warentover 7 years ago
<p><pre><code> When finishing a level, the game would reboot the console and restart itself with a command-line argument (the name of the level to start) ... into the next level. Voila, the perfect(?) way to clear all memory between levels. </code></pre> OH MY<p>At 22 years old, this is one of those moments where I&#x27;m in awe of the strange issues and workarounds that existed merely ~5-10 years ago which I&#x27;ll probably never have to deal with. Very funny!
评论 #15947374 未加载
评论 #15948068 未加载
tomalphaover 7 years ago
Problem solving within a constrained system. It’s fun stuff and I always find it amazing how adversity and particularly time pressure can bring out the ingenuousness in people.<p>I guess wartime inventions are possibly an extreme example (google Hobart’s Funnies some time for some good clean ingenuity), but shipping console games to a deadline seems to have a similar effect.
Const-meover 7 years ago
RAM usage still matters a lot. Not only because consoles, also because RAM usage often translates to storage bandwidth, and CPU-GPU bandwidth.<p>Some of the tricks still apply today. For example, modern GPUs support all kinds of weird texture formats. Here’s a link for PC: <a href="https:&#x2F;&#x2F;msdn.microsoft.com&#x2F;en-us&#x2F;library&#x2F;windows&#x2F;desktop&#x2F;hh308955(v=vs.85).aspx" rel="nofollow">https:&#x2F;&#x2F;msdn.microsoft.com&#x2F;en-us&#x2F;library&#x2F;windows&#x2F;desktop&#x2F;hh3...</a> Other platforms have conceptually similar stuff.
torgardover 7 years ago
&gt; Ultimately Crash fit into the PS1&#x27;s memory with 4 bytes to spare. Yes, 4 bytes out of 2097152. Good times.<p>Wow. I am absolutely <i>blown away</i> by this.
评论 #15948946 未加载
评论 #15948792 未加载
kaushiksover 7 years ago
Here&#x27;s another interesting story from the DOS days:<p><a href="https:&#x2F;&#x2F;blogs.msdn.microsoft.com&#x2F;larryosterman&#x2F;2004&#x2F;11&#x2F;08&#x2F;how-did-we-make-the-dos-redirector-take-up-only-256-bytes-of-memory&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blogs.msdn.microsoft.com&#x2F;larryosterman&#x2F;2004&#x2F;11&#x2F;08&#x2F;ho...</a>
fnlover 7 years ago
Makes me wonder why Rust isn&#x27;t popular with game devs. Wouldn&#x27;t Rust&#x27;s borrow checker and resource management at compilation time make most of the described memory reclaiming issues obsolete?
评论 #15947962 未加载
评论 #15947898 未加载
评论 #15948666 未加载
评论 #15948292 未加载
评论 #15947668 未加载
评论 #15950231 未加载
评论 #15949224 未加载
评论 #15947578 未加载
throwmeaway32over 7 years ago
This is giving me fond memories of things I had to do or had heard about from colleagues:-<p>- To improve game loading speed of a CD - Load level on PC from hardisk, log all filenames loaded to a txt file and then use that to order the files when writing to the final CD.<p>- Load all files into PS1 devkits memory, write out all memory in a binary blob to the harddisk, burn that memory image to CD to use for fast level loading (just load it in a single fread(..).<p>- have separate executables for different levels which had different features, to save memory.<p>- Write a small block allocator to make &lt;256byte allocations quicker and more efficient.<p>- Find a tiny piece of memory in the PS2 IOP chip which doesn&#x27;t get wiped on a devkit reboot (for some reason) and use that as &#x27;scratch&#x27; space to write log messages to track down a hard to repro crash that rebooted the kit.<p>- Change the colour of the tvs border to different colours to track down a race condition that only existed on burnt disks and we had no debugger. The border colour setting code was quick enough to not affect the race condition, so choose some places in code to arbitrarily set to certain colours, burn the disk, test it, when it crashed see what colour the border was, then put some more colours in possible areas, re burn the disk and etc (so basically binary search the code areas using border colours).<p>- Use compiler optimisations settings for &#x27;size&#x27; instead of &#x27;speed&#x27; as the smaller executable code size meant you stayed in the DCache more which actually made the code quicker than compiling for &#x27;speed&#x27; which resulted in generally larger code.<p>- Burn a master CD image for publisher, get the game ID code wrong, open up the disk image file in a hex editor and manually edit it rather than go through the whole build process again.<p>- have no build machine (Gold master got made off whatever code the leads machine had).<p>- Use sourcesafe (no atomic checkins....)<p>- Use a few batch files and a directory share for &#x27;source control&#x27; of art assets.<p>- Have values in config files we gave to games designers which did nothing (this was accidental but they swore changing them made a difference to the game).<p>- Have a advertising deal with a company to have a special cheat code in the game to unlock some stuff, the programming code that does this has a bug that ships that means you have to alter the code incorrectly to get it to work....so tell the company that &#x27;Your code was too easy so we made it harder&#x27;.<p>- Have a developer write code like this as he swore that passing a extra parameter would have slowed the game down:- (psuedo code, but original was in C)<p>Do stuff(int val)<p>{<p>foo * bar;<p>If (val&lt;10)<p>{<p>bar = gStuff[val];<p>}<p>else<p>{<p>bar = (foo* )val;<p>}<p>}