Whenever you are building an application that’s memory intensive, you are bound to run into memory issues. Those out of memory errors are painful to deal with, especially when they happen during production. Before putting your code on your server, you need to make sure that it can handle the application’s memory requirements. But even if you are careful, something might still go wrong and you might end up running into memory issues. One of the easiest ways to deal with this is by adding some swap space. Now how will it help our case? How can we use it on Ubuntu? Continue reading “How To Add Swap Space On Ubuntu”
Tag: Memory
What Is External Sorting?
Sorting is one of the most common things we do in programming. We are given a bunch of numbers and we want to arrange them according to some rule. Let’s say we want to arrange them in ascending order. To sort these numbers, people tend to use a sorting algorithm that takes place entirely within the memory of a computer. The memory we are talking about is the RAM. Here, we take all the numbers and store them in the memory so that we can sort them. This is possible only when the amount of data is small enough to be stored in the memory. What if we have a hundred trillion numbers to be sorted? It’s too big to be stored in the computer’s memory. How do we do it? Continue reading “What Is External Sorting?”
Why Do We Need size_t?
In statically typed programming languages, datatypes play a very important role. Some of common datatypes are int, float, char, double, etc. Different datatypes have different functionalities and we use them depending on our requirements. In modern C++ code, the type “size_t” is used a lot of instead of int or unsigned int. It appears in many different scenarios like parameters to string functions, standard template library (STL), etc. Ever wondered why we need to use it in the first place? Does it have any real advantage? Continue reading “Why Do We Need size_t?”
Why Is Python Slow?
When people talk about speed in the world of programming languages, they usually center the discussion around compiled vs interpreted languages. In this post, we will discuss two of the most famous languages on this planet, Python and C. I was recently playing around with this and I made a few pleasant discoveries. So I thought I should share them here. One of the biggest reasons as to why Python is slower than C is because of the dynamic typing feature in Python. While it may be true that dynamically typed programming languages are slower than statically typed languages, it may not be the major factor slowing down your Python code. The dynamic typing feature of programming languages like Python makes the interpreters harder to optimize. I guess this is the cost of having an extremely beginner-friendly language! But one thing to note is that there is a big difference between interpreter being harder to optimize and your code being slow. We’ve had years of research focusing on the best way to perform type checking at runtime in these languages, thus making this overhead negligible. So how do we understand why Python code is slower than C code? How do we write Python code that’s not slow? Continue reading “Why Is Python Slow?”
Exploring The Hidden C++ Features
People have been using C++ for a long time now and most of us think that we are pretty well versed with it. Interestingly enough, as we spend more time with something, we keep discovering more things about it. I love it when the thing you have been using for so long turns out to have powerful hidden features. I encounter a lot of C++ in my day-to-day life and so I end up spending a lot of time with it. Over time, as I delved deeper into C++, I came across some abstruse features, some of which really surprised me! So I thought I should write about them. Let’s see what they are. Continue reading “Exploring The Hidden C++ Features”
What Is Tail Recursion?
Programmers deal with recursion all the time. It’s actually quite a nice concept, but not a lot of people use it because of the mystery associated with it. To be honest, there’s no mystery as such! Sometimes, a problem is too complex to solve because it is too big. If we can break the problem down into smaller versions of itself, we may be able to find a way to solve one of these smaller versions and then be able to build up to a solution to the entire problem. This is the entire idea behind recursion. Recursive algorithms break down a problem into smaller pieces which you already know the answer to. We can solve these smaller problems by applying the same algorithm to each piece, and then combine the results. I have discussed all this in complete detail here. Now that we have talked about recursion, what exactly is the title of this blog post referring to? What exactly is tail recursion and why do we need it? Continue reading “What Is Tail Recursion?”
What Is Pointer Casting?
We all know how important pointers are in C++. A pointer is basically an object that contains an address to a variable. We can use this address to access the value stored in that variable, and that variable is located somewhere in the memory. It’s like how we use an address to locate someone in real life! An interesting thing to note about pointers is that although they contain addresses, they don’t really care about what they are actually pointing to. It’s like looking at an address in real life and not knowing if it’s a house or a clothing store. Now you might ask, why is such a thing relevant in programming? Can we take actually advantage of this? Continue reading “What Is Pointer Casting?”
How To Deal With Buffer Overflow
You must have encountered the word ‘buffer’ somewhere in your life. In everyday usage, buffer refers to something that acts as an intermediary between two things that don’t get along. It’s a shield which moderates the impact of one thing over the other. In the programming world, buffer refers to an area where we temporarily store data before moving it to another place. Perhaps the most famous example would be copy-paste. When you copy something, it is stored in the buffer until you paste it somewhere. This concept is used extensively while building software systems and it’s important to make sure that the buffer behaves nicely at all times. Now you might ask, what does buffer behavior refer to? Why would it not behave nicely at all times? Continue reading “How To Deal With Buffer Overflow”
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”
EXC_BAD_ACCESS Problem In Objective-C
So you finally stumbled upon this error. If you have been working with Objective-C, this is bound to happen. When you release the memory of an object that has already been released, and then try to go back to your previous UIViewController, you will encounter this error. One of the possible reasons could be that you must be using Automatic Reference Counting (ARC) in your project. ARC was a new feature introduced in iOS 5.0 to take care of memory management. This is a very useful feature, but it can also cause errors if you don’t understand what’s happening under the hood. Continue reading “EXC_BAD_ACCESS Problem In Objective-C”