7

How does memory allocation affect battery usage? Does holding lots of data in variables consume more power than performing many iterations of basic calculations?

P.S. I'm working on a scientific app for mac, and want to optimize it for battery consumption.

jimmym715
  • 1,512
  • 1
  • 16
  • 25
NoobDev4iPhone
  • 5,531
  • 10
  • 33
  • 33

3 Answers3

11

The amount of data you hold in memory doesn't influence the battery life as the complete memory has to be refreshed all the time, whether you store something there or not (the memory controller doesn't know whether a part is "unused", AFAIK).

By contrast, calculations do require power. Especially if they might wake up the CPU from an idle or low power state.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • "Especially if they might wake up the CPU from an idle or low power state." are you sure about that? I believe Mac OS X has the CPU entering and leaving it's low power state in between individual keystrokes, even while typing fast. Surely they wouldn't do that if there was some extra power tax to adjusting the consumption. I could be wrong of course. – Abhi Beckert Dec 12 '11 at 10:03
  • 1
    I meant that if the calculation wasn't done and the CPU would have been able to stay in idle/low power mode it would use a lot less power. I have no idea whether the act of switching from/to low power mode has a penalty. – DarkDust Dec 12 '11 at 10:11
2

I believe RAM consumption is identical regardless of whether it's full or empty. However more physical RAM you have in the machine the more power it will consume.

On a mac, you will want to avoid hitting the hard drive, so try to make sure you don't read the disk very often and definitely don't consume so much RAM you start using virtual memory (or push other apps into virtual memory).

Most modern macs will also partially power down the CPU(s) when they aren't very busy, so reducing CPU usage will actually reduce power consumption.

Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
  • +1, if the memory consumption forces increased use of hard disk it'll indeed need a lot more power. – DarkDust Dec 12 '11 at 10:13
1

On the other hand when your app uses more memory it pushes other apps cache data out of the memory and the processing can have some battery cost if the user decides to switch from one to the other, but that i think will be negligible. it's best to minimize your application's memory footprint once it transitions to the background simply to allow more applications to hang around and not be terminated. Also, applications are terminated in descending order of memory size, so if your application is the largest one existing in the background, it will be killed first.

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115