Tuesday, February 27, 2007

A long-awaited Chinese New Year

Since I came to Japan 6 years ago in 2001, I have been spending Chinese New Year in Japan sitting for exams almost every year. This year I finally had a chance to go back to my hometown to celebrate Chinese New Year with my family. Everything is so nostalgic, the firecrackers, the angpows, the food, the people. Although I haven't made it to finish my report before I went back to Malaysia on 10th Feb, thus having to spend the first week doing report at home, I am very contended with this short trip.

After spending the first week doing report, I met up with someone I had wanted to get close to but had never been too close before. We went to shop, went to Old Town(a new cafe chain store in Malaysia), went to a movie, went to karaoke and spent almost everyday together the week after the 1st day of CNY. I even sent her off to work early in the morning. Honestly, I haven't been so energetic for a very long time.

Then, we spent a really sweet night on the beach. Soft music flowing from her mobile phone through the air along with the soothing sea breeze. And the sky was so full of stars(alright, not the whole sky but part of it). The atmosphere was just so perfect! We talked about many things, her life, my life, and the probabilities in the future.

However, time seemed to pass faster when you enjoy it. Soon I had to come back to Japan to continue what I had left off. Well, among the holidays that I spent in Malaysia, this is definitely the one that I will never forget.

Thursday, February 08, 2007

Stack Overflow: How to make the stack bigger?

Hi, fellas!

It has been a long time since I have posted something really technical. So here I am again.

We have been asked to implement a quicksort-based selection algorithm and another one based on random sampling to compare them to each other in one of the lectures. But wait. I am not going to tell about these algorithms. What I want to say here is more general, more system related.

Ok, by looking at the algorithms, everyone can tell that the quicksort-based method, because of its simplicity, runs faster in a usual case when the target array size is small. So, in order to be able to say that "the random sampling based method performs better when the size of the data set is large", I have to make sure the sample size is large. And here the problem begins!!!

When you run a program, the operating system puts your program into the RAM. At the same time, it also allocates some spaces for the consumption by the program, in case it needs it. There are two types of allocated memory, stack and heap. I don't really remember but I think that the stack is used for function calls and variables, whereas the heap is used when you allocate memory dynamically by calling malloc().

Stack overflow occurs when your program needs more memory than allocated to it. In my case, I need a lot of space to make sure the data set is large enough to see the difference between the algorithms, so the default stack size allocated by MinGW gcc is not enough for me. I later found out also that stack size allocated to a program is handled by the operating system it is run on, so there is no sure way to turn around this problem. Luckily I came upon this file. It provides exactly what I wanted. I link to it here in case I will need it again some day, and maybe you would find it useful, too.

It is kind of late now so I have got to go.

Good night.