Let’s say you are working with images for your project. A lot of times, when you have to work across multiple platforms, the encoding doesn’t remain the same. In these scenarios, you cannot process images directly by treating them like 2D matrices. One of the most common image formats you will comes across is JPEG. If you are working on the same platform using a library like OpenCV, you can directly read JPEG files into 2D data structures. If not, you will have to read it into a byte array, process it and then encode it back. How do we do that? Continue reading “Reading JPEG Into A Byte Array”
Tag: C
C++ Vector Memory Release
When you use C++ STL, it takes care of freeing up memory after a variable goes out of scope. But let’s say you have some code that needs the memory to be freed up immediately. This can happen under many circumstances when you are working under constrained resources. One of the more popular STL containers is ‘vector’. Let’s say you have declared a bunch of those in your code and you want to free them up manually. You may think that using clear() on that vector might take care of the situation, but it doesn’t. You can call clear(), and it will destroy all the objects, but it will not free up the memory. So how do we do it? Continue reading “C++ Vector Memory Release”
Random Number Generators In Programming
If you have fiddled around enough with C/C++/Objective-C, you must have noticed that if you use rand() function on its own, it gives the exact same numbers every time. Now how is that possible? Isn’t rand() function supposed to generated completely random numbers in a given range? The reason for this has something to do with the seed value. If you use the same seed value every time, then you will get the same numbers. Continue reading “Random Number Generators In Programming”
Expected Expression Error
You tried to declare a variable after a ‘case’ statement and it showed an error. If that’s the reason you are here, then read on. This must actually be surprising to most people familiar with C++ programming because C++ allows us to declare variables almost anywhere in the program. In fact, declaring them close the first use is actually a good practice. So why can’t you declare variables after a case label in a switch statement? Continue reading “Expected Expression Error”