Last Updated: February 25, 2016
·
1.771K
· ccubed

Memory or CPU Intensive. Which do you make?

When you made that last project, did you consider whether or not the code you were writing was Memory or CPU intensive? You probably didn't unless you program for embedded devices in which case you probably spend a lot of time worrying about this. It's a fundamentally important question really in the world where computer hardware can be so different and so few and far between. Programs are run on multiple machines and sometimes with differing hardware. Sometimes, even in a controlled environment such as a business, that hardware can be taxed by other applications that are required to run at the same time as yours. Why aren't you considering whether your code is Memory or CPU Intensive? Do you understand the difference?

It amuses me that this is a topic that never comes up. If you do a Google search for any combination of the above and code or programming, you really don't get that many results! Some of the results are simple questions about why this program is one or the other and fewer yet are questions about where to find code examples for both. It amuses me from the perspective that in general it has become an accepted fact that we no longer need to worry about either. More and More code today gets released with hampering and sometimes fatal memory leaks. This is a simple, basic concept that anyone learns with or without a degree. Yet it happens now more than ever and on commercial products no less. It just goes to show the abandon with which we code now-a-days.

So I got to wondering. Does anyone even think about this anymore? Or even know how to tell which is which? Or care? Embedded systems designers are of course exempt from this question. They program for devices that by their nature require them to have an understanding of how much power and memory it has available. That's not to say that embedded systems don't have their own problems or that people that code for them don't have memory leaks or make the mistake of not caring about how intensive their application is, but they're generally less guilty of it by the nature of what they program for.

Why should I care? That's the new question right? Computers now-a-days come standard with dual core or quad core processors, sometimes with 8 logical cores, and at least 4GB of memory, so why should I care about whether my code is Memory or CPU Intensive? There is a one word answer to these questions: Speed. Even though it can be a relatively normal expectation today that you probably don't have to worry about these things in general, but that doesn't mean you shouldn't. It can solve numerous problems and overall increase speed by being able to push certain activities to memory and certain activities to CPU. In other words, understanding the relationship allows you to, in a way, make the computer work for you instead of against you.

Ultimately, Computers work against us. They're far too general a tool and that's their greatest strength and weakness. Your computer is a calculator, calendar, email client, web browser, game player, music player, video player, spreadsheet making behemoth, but there in lies the issues. It's built to do all of that effectively but not great. Knowing how to balance between Memory and CPU can make your programming better.

I plan on writing some tutorials about this topic. How to plan for Memory and CPU Intensive code and how to balance both in projects. At the moment, this post was meant as an introduction to the topic and also as my first pro tip. See you later. I'll probably write the first tutorial tonight or tomorrow.

1 Response
Add your response

When developing for mobile devices, especially Android (given it's insane fragmentation, and the extremely high probability that at least some of your end-users will have low-end low-memory devices), you have to really think about what your app is doing and how both the cpu cycles and memory use can be reduced to the bare minimum.

over 1 year ago ·