freemyipod r715 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r714‎ | r715 | r716 >
Date:22:56, 21 May 2011
Author:user890104
Status:new
Tags:
Comment:
Beeper: optimize memory allocation a bit
Modified paths:
  • /apps/beeper/main.c (modified) (history)
  • /apps/beeper/mario.txt (modified) (history)

Diff [purge]

Index: apps/beeper/main.c
@@ -93,15 +93,19 @@
9494
9595 void playsong(void *buf, size_t size) {
9696 int i;
97 - unsigned int cycles[size / 8], lengths[size / 8];
 97+ unsigned int *cycles, *lengths, count;
9898
99 - for (i = 0; i < size / 8; ++i)
 99+ count = size / 8;
 100+ cycles = malloc(count * sizeof(unsigned int));
 101+ lengths = malloc(count * sizeof(unsigned int));
 102+
 103+ for (i = 0; i < count; ++i)
100104 {
101105 cycles[i] = *((unsigned int *)(buf) + i + i);
102106 lengths[i] = *((unsigned int *)(buf) + i + i + 1);
103107 }
104108
105 - for (i = 0; i < size / 8; ++i)
 109+ for (i = 0; i < count; ++i)
106110 {
107111 if (0 == cycles[i])
108112 {
@@ -111,6 +115,9 @@
112116
113117 singlebeep(cycles[i], lengths[i]);
114118 }
 119+
 120+ free(lengths);
 121+ free(cycles);
115122 }
116123
117124 EMCORE_APP_HEADER("Beeper", main, 127)
Index: apps/beeper/mario.txt
@@ -80,4 +80,5 @@
8181 p 0 8
8282 c 5 8
8383 d 5 8
84 -b 4 8
\ No newline at end of file
 84+b 4 8
 85+