Is “Out Of Memory” A Recoverable Error?

It really depends on what you’re building. It’s not entirely unreasonable for a webserver to fail one request/response pair but then keep on going for further requests. You’d have to be sure that the single failure didn’t have detrimental effects on the global state, however – that would be the tricky bit. Given that a … Read more

How does this program work?

That’s because %d expects an int but you’ve provided a float. Use %e/%f/%g to print the float. On why 0 is printed: The floating point number is converted to double before sending to printf. The number 1234.5 in double representation in little endian is 00 00 00 00 00 4A 93 40 A %d consumes … Read more

Does an unused member variable take up memory?

The golden C++ “as-if” rule1 states that, if the observable behavior of a program doesn’t depend on an unused data-member existence, the compiler is allowed to optimized it away. Does an unused member variable take up memory? No (if it is “really” unused). Now comes two questions in mind: When would the observable behavior not … Read more

C Memory Management

There are two places where variables can be put in memory. When you create a variable like this: int a; char c; char d[16]; The variables are created in the “stack“. Stack variables are automatically freed when they go out of scope (that is, when the code can’t reach them anymore). You might hear them … Read more

memory_get_peak_usage() with “real usage”

Ok, lets test this using a simple script: ini_set(‘memory_limit’, ‘1M’); $x = ”; while(true) { echo “not real: “.(memory_get_peak_usage(false)/1024/1024).” MiB\n”; echo “real: “.(memory_get_peak_usage(true)/1024/1024).” MiB\n\n”; $x .= str_repeat(‘ ‘, 1024*25); //store 25kb more to string } Output: not real: 0.73469543457031 MiB real: 0.75 MiB not real: 0.75910949707031 MiB real: 1 MiB … not real: 0.95442199707031 MiB … Read more

Sound overlapping with multiple button presses

Declare your AVAudioPlayer in the header the viewController ( don’t alloc a new one each time you play a sound). That way you will have a pointer you can use in a StopAudio method. @interface myViewController : UIViewController <AVAudioPlayerDelegate> { AVAudioPlayer *theAudio; } @property (nonatomic, retain) AVAudioPlayer *theAudio; @end @implementation myViewController @synthesize theAudio; – (void)dealloc … Read more