iPhone crashing when presenting modal view controller

I have modified it slightly so that the loading view is shown after a tiny delay, and this works fine! So it appears to be something within the same event loop! – (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Show load [self performSelector:@selector(doit) withObject:nil afterDelay:0.1]; } – (void)doit { [self presentModalViewController:loader animated:YES]; }

How to check memory allocation failures with new operator?

Well, you call new that throws bad_alloc, so you must catch it: try { scoped_array<char> buf(new char[MAX_BUF]); … } catch(std::bad_alloc&) { … } or scoped_array<char> buf(new(nothrow) char[MAX_BUF]); if(!buf) { //allocation failed } What I mean by my answer is that smart pointers propagate exceptions. So if you’re allocating memory with ordinary throwing new, you must … Read more

Modern C++ idiom for allocating / deallocating an I/O buffer

Basically, you have two main C++-way choices: std::vector std::unique_ptr I’d prefer the second, since you don’t need all the automatic resizing stuff in std::vector, and you don’t need a container – you need just a buffer. std::unique_ptr has a specialization for dynamic arrays: std::unique_ptr<int[]> will call delete [] in it’s destructor, and will provide you … Read more

Why do C and C++ compilers place explicitly initialized and default initialized global variables in different segments?

Neither language C or C++ has any notion of “segments”, and not all OSs do either, so your question is inevitably dependent on the platform and compiler. That said, common implementations will treat initialized vs. uninitialized variables differently. The main difference is that uninitialized (or default 0-initialized) data does not have to be actually saved … Read more

Why does C# memory stream reserve so much memory?

Because this is the algorithm for how it expands its capacity. public override void Write(byte[] buffer, int offset, int count) { //… Removed Error checking for example int i = _position + count; // Check for overflow if (i < 0) throw new IOException(Environment.GetResourceString(“IO.IO_StreamTooLong”)); if (i > _length) { bool mustZero = _position > _length; … Read more

tech