fprawn
In the general case, however, if allocating 100 bytes fails, reporting that error is also likely to fail. An actual memory allocation failure on a modern computer running a modern OS is a very rare and very bad situation. It's rarely recoverable.
It's not bad to handle allocation failures, but in the vast majority of cases it's very unreasonable to do so. You can write code for it if you want, have fun.
And just to be completely clear, I am ONLY talking about calls to malloc, new, realloc, etc. NOT to OS pools or anything like that. Obviously, if you allocate a 4Mb buffer for something (or the OS does for you), you expect that you might run out. This is ONLY in regards to calls to lower level heap allocators.
I don't think you'll find any experienced programmer recommending that you always check the return from malloc. That's completely absurd. There are always exceptions to the rule, however.
Memory can be allocated beyond RAM size, so by the time a failure occurs your program really should crash and return its resources.
Embedded systems have fewer resources and some will not have virtual memory and so the situation will be different. But unless you know better, the best practice is still to not check the return from allocators. Running out of memory in a program intended for an embedded platform should be considered a bug.
10+ years C/C++ video game development, scientific visualization, and real time image processing.
Polyglot programmer that works mainly in C/C++, Python, Perl, and PHP on Android/iOS, Windows/Mac/Linux, embedded, game consoles, backend servers.
Looking to help optimize low level code, work on 2D or 3D visualizations and games. I work fast, write clean code and can help mentor junior developers.
contact: [email protected]
It's upsetting how dismissive of his work he can be, he deserves to be proud of this, I certainly would be.
I guess there won't be much agreement here on HN, but this deserves to be recognized as an amusing and clever solution to a problem. Even if the problem is self created.
PHP is great for doing quick and dirty dynamic web pages. So what if it doesn't scale out to a million line program?
In the event that the destination buffer is much larger than the source, that additional computation is trivial (it's the same calculation that's already being done for each and every pixel). As it only needs to be additionally done on the corners, not per-pixel, the additional time spent should be quite minimal.
The shearing method in the article is genuinely clever and totally cool, but I just can't shake the feeling that even on 1980s hardware, this method would be better. On modern hardware, there's no question, it's still used to this day. Nowhere near as cool, though.
This method is as simple to code and doesn't suffer from the missing-pixel aliasing problem of the simple method of the article, and is also capable of higher quality results than the shearing method.