Another round of sparring partners for Prophet3

Back in early March I added aspiration windows to Prophet with a window of 1/3 pawn, as well as some futility pruning and delta pruning. My schedule hasn’t allowed me to do a lot of work on the code since then, so I took advantage of the time to find some new sparring partners. The results are in the table below.

These games — almost 200k of them — are played at 3+0.5. That is, the clock starts at 3 seconds and 1/2 second is added after each move. That may seem like a fast game but when you’re going for quantity, it’s actually slower than I’d like. That’s about as fast as I could go on my older test system without getting a lot of time forfeits.

Rank Name Elo games score oppo. draws
1 plisk 98 25092 62% 17 18%
2 tjchess 98 32400 62% 11 21%
3 jazz 74 33286 60% 4 19%
4 myrddin 49 31082 58% -7 18%
5 Horizon 2 31080 51% -3 17%
6 tcb -5 31080 50% -2 18%
7 prophet3-20170319 -11 42068 45% 27 23%
8 jumbo -12 31240 49% -2 19%
9 madeleine -12 31240 49% -2 19%
10 Beowulf -94 24900 39% -17 19%
11 prophet2 -104 21700 39% -30 18%
12 matheus -107 21700 39% -29 18%

I’ve actually dropped Beowulf, Prophet2, and Matheus off the active list. The others should keep Prophet busy for a while.

With summer coming and other commitments starting to wind down for a while, I’ve started working again. The latest version seems to be about +10 ELO above this version.

Posted in Computer Chess, Prophet | Leave a comment

chess4j 3.2 is released and it’s magic!

I just released chess4j 3.2. This release is purely about optimizing for speed. That is, there are no changes to the search or evaluation terms.

chess4j is now a bitboard engine, and uses magic bitboards for move generation. Simply by replacing some loops over all squares with loops over (possibly sparsely populated) bitboards, and probably most importantly getting rid of some managed collections stuff, chess4j 3.2 is 4-5x faster than 3.1. In a head to head match of almost 700 games with 3.1, 3.2 scored 79% which translates into a 200-250 elo gain.

One other important difference is that the opening book is now off by default. If you want to use the opening book included with the release, you must add “-book=book.db” to the command line. (This is done in the included chess4j.bat.)

I think I can still get some more ELO just off speed optimizations and efficiency improvements (such as splitting up capture and noncapture move generation), so there will probably be one more release in the 3.x line before moving onto 4.0. The 4.x line will be focused on parallel search.

As usual you can grab the latest and greatest from the project website. Enjoy!

Posted in chess4j, Computer Chess | Leave a comment

Prophet’s sparring partners

Several months ago I decided to get a little more rigorous about how I test changes to Prophet. With previous versions of Prophet, I would make a change, run some test suites consisting of a few hundred or a thousand tactical positions, play a few games online to convince myself the change was good, and that was it. That doesn’t really cut it any more though. Fruit and other engines that have followed suit have shown the importance of a having a solid testing methodology that accurately measures how effective changes are. So, to that end, I found some sparring partners and took my first measurements:

Rank Name Elo games score oppo. draws
1 matheus 101 7360 67% -20 16%
2 prophet2 86 7360 64% -17 14%
3 lime 35 7360 56% -7 12%
4 gerbil -25 7360 46% 5 15%
5 prophet3-20160903 -54 8000 41% 12 17%
6 elephant -138 7360 28% 27 11%

Then Christmas happened, and I found myself with a little spare time to work on Prophet. I implemented bitboards, and then magic bitboards, and a few other speed optimizations. Suddenly it looked like I needed some new sparring partners!

Rank Name Elo games score oppo. draws
1 prophet3-20170118 91 24436 68% -42 17%
2 matheus 65 10648 58% 5 20%
3 prophet2 23 10649 51% 10 16%
4 lime -24 10649 44% 17 13%
5 gerbil -81 10643 35% 24 14%
6 elephant -191 10648 21% 39 10%

Here is what I ended up with. I like this a lot, as Prophet3 is right in the middle with some engines below and above. That seems like a pretty good cross section. As Prophet3 continues to improve, I’ll just add newer strong engines to the mix and drop the bottom ones off.

Rank Name Elo games score oppo. draws
1 myrddin 84 4811 63% -7 18%
2 tcb 46 4810 57% -4 18%
3 Horizon 30 4812 55% -2 17%
4 jumbo 19 4972 53% -2 18%
5 prophet3 7 12733 51% -2 22%
6 madeleine -26 4972 46% 4 20%
7 matheus -36 4812 44% 4 20%
8 Beowulf -67 4812 39% 7 20%
9 prophet2 -71 4812 39% 7 18%

Posted in Computer Chess, Prophet | Leave a comment

chess4j 3.1 is released

I just released version 3.1 of chess4j, my Java based chess engine. This version is about 100 elo stronger than 3.0. The key differences are:

  • The Groovy language is no longer used. Groovy is a fine language for some purposes. chess4j didn’t make heavy use of it but did use it for some I/O type classes, which I wrote about in this post. Unfortunately, it was a constant struggle with my IDE of choice (STS). It constantly balked and complained about the Groovy classes. I had hoped that in time IDE support would improve but in the end I just got tired of constantly messing around with it. On a positive note the chess4j jar file went from 11.5 mb to 4.5 mb.
  • Some modest search improvements, worth about 20 elo.
  • Added pondering. This means that when it’s the opponent’s turn to move, chess4j is already thinking about its response. If chess4j correctly predicted what the opponent will play, then it is that far ahead in formulating a response (it may even be able to play its move instantly). Seems to be worth about 80 elo.

In my testing, chess4j 3.1 scores 53% against 3.0 in a 1000 game match without pondering, and 64% in a 1600 game match with pondering.

I have my sights set on a parallel search for the 4.0 release, but I think there will be another minor release or two before that to work on search speed optimizations.

You can grab the latest and greatest from the project website. Enjoy!

Posted in chess4j, Computer Chess | Leave a comment

Swafford Family Tour de States – Chapter II Part II

This is the second installment about our second cross country trip, focusing on the northwest. In case you missed it: Chapter II part I.

June 25 – Albany OR – Just an overnight stay on the way to Seattle.

I love this picture of the truck in front a big rig… shows just how much we were hauling!

bigrig

And once again we finally made it to “the other side!”

20160625_175129

June 26-July 1 – Seattle WA – one of my favorite cities. The first two pictures here are the view from the top of the Space Needle in a restaurant we ate lunch at. We also got coffee from the original Starbucks and visited the fish market.

20160628_134226

20160628_135449

20160628_151527

20160628_152501

We did have a near catastrophe here. Not paying attention at a gas pump, I filled our diesel truck full of unleaded gas! That set us back a few days and caused me a lot of anxiety. That won’t ever happen again!

July 2 – Pendleton OR

20160702_144515

July 3 – Jerome ID – Not a lot going on in Jerome, but one of Amy’s long time Internet friends lived here. She got to meet her face to face and have lunch with her.

20160703_140955

July 4-7 – Yellowstone – there is no way I could describe the beauty of this place, so I took a lot of pictures. One of the things that was striking to me (other than boiling puddles of water) is the grassy forest floors. It was very different than the forests back east. It almost felt like we were walking to the Shire.

20160704_172606

20160705_142603

20160705_144138

20160705_155717

20160705_163635

20160705_174816

20160705_174938

20160706_135055

20160706_143443

20160707_130825

20160707_133754

20160707_135013

20160707_161545

20160707_162155

20160707_164517

20160707_165046

20160707_191905

20160707_191909

20160707_220739

July 8-10 – Billings MT – the battle of Little Big Horn. RIP General Custer. He’s not actually buried here but this is where he fell as he was surrounded by Indians (Native Americans).

20160710_144312

July 11-15 – Rapid City SD – lots going on in this area. We did a drive through tour of the Badlands, went to Devil’s Tower, and Mt. Rushmore. Amy really loved this area.

20160715_163508

20160715_155748

20160712_151350

20160715_153650

20160715_153527

20160713_151933

July 16-17 – Bismarck ND – we camped in Bismarck but we stayed here just to take a day trip up to Minot, which is not too far from the Canadian border. The remarkable thing about Minot (“Magic City”) is that I was born there! And there is a cool Stave church.

20160717_141530

20160717_142024

20160717_144128

July 18 – Nowhere MT

July 19-23 – Minneapolis MN – Mall of America!! And we timed it just right so that we were here over Ailsa’s birthday. What else could a girl want other than to be in the biggest mall in America on her birthday with some spending money??

20160720_115235

20160720_195629

July 24-26 – Madison WI – home of “House on the Rock.” That place is insane.

20160726_122333

20160726_142435

20160726_143959

July 27-28 – Elkhart IN – just a stop over. We were going to see where Zinger travel trailers are made but unfortunately the timing didn’t work out. They only did public tours on certain days of the week.

20160728_140653

July 29-31 – Dayton OH – birthplace of Orville and Wilbur Wright. We met up with Amy’s long time friend Tanya to tour the Wright bicycle shop and a museum, as well as the Cincinnati zoo.

20160730_144228

20160730_151150

20160731_140320

20160801_091730

Aug. 1-2 – Wytheville VA – we were getting into familiar territory here. We took a day to do a little day hiking on the AT so that Jamie could finish his hiking merit badge.

20160802_130830

20160802_140616

20160802_165853

wytheville_campfire

Aug. 3 – HOME.

What an amazing journey. The best part was the time with the family, completely disconnected from the rest of the world. I miss that more than anything.

Posted in Travel | Leave a comment

Prophet is back

After a VERY long absence from server play, the rewrite of my chess engine Prophet is finally far enough along to play some games online. The engine itself has been capable of play for a little while now, but I’ve establishing a testing routine and wanted to get an opening book.

Previous versions of Prophet had a custom book format, using fseek() and the like on a binary file. I may go back to that at some point but right now Prophet 3 uses SQLite to query the book built for chess4j.

Anyway, the engine has been online ICC most of the day:


67: + 1632 W 1469 brittabeast [ br 5 3] D11 Res Nov 30 16 15:29
66: + 1622 B 1479 brittabeast [ br 5 3] B03 Mat Nov 30 16 15:23
65: + 1611 W 1466 ituchesstech [ br 5 3] D08 Mat Nov 30 16 15:13
64: + 1600 B 1533 Knipshun [ br 5 3] A00 Res Nov 30 16 14:56
63: + 1586 W 1547 Knipshun [ br 5 3] C00 Res Nov 30 16 14:53
62: + 1570 B 1563 Knipshun [ br 5 3] A00 Res Nov 30 16 14:49
61: + 1553 W 1092 Darkpower [ br 5 3] A04 Res Nov 30 16 14:42
60: + 1551 B 1094 Darkpower [ br 5 3] B00 Res Nov 30 16 14:37
59: + 1549 W 1096 Darkpower [ br 5 3] D35 Res Nov 30 16 14:33
58: + 1547 B 1098 Darkpower [ br 5 3] B02 Res Nov 30 16 14:29
57: + 1545 W 1100 Darkpower [ br 5 3] C41 Res Nov 30 16 14:23
56: + 1543 B 1102 Darkpower [ br 5 3] B07 Res Nov 30 16 14:16
55: + 1541 W 1104 Darkpower [ br 5 3] D31 Res Nov 30 16 14:14
54: + 1539 B 1106 Darkpower [ br 5 3] B06 Res Nov 30 16 14:04
53: + 1537 W 1108 Darkpower [ br 5 3] D37 Res Nov 30 16 13:59
52: + 1534 B 1111 Darkpower [ br 5 3] B01 Res Nov 30 16 13:53
51: + 1531 B 1520 zalk [ br 5 3] A00 Res Nov 30 16 13:50
50: + 1514 W 1537 zalk [ br 5 3] B06 Res Nov 30 16 13:45
49: + 1495 W 1233 TT [ br 5 3] A04 Fla Nov 30 16 13:33
48: + 1695 B 1431 amr [ Br 2 1] B00 Mat Nov 30 16 13:28

20/20 isn’t too bad! Granted, it helps that it was vastly underrated, but still…what fun 🙂

Posted in Computer Chess, Prophet | Leave a comment

Swafford Family Tour de States – Chapter II Part I

On May 17th we set out on the second leg of our Tour de States. This time our focus would be on the Northwest. We would start out going through Tennessee and up through St Louis MO, then across to Kansas, through to Colorado, Utah, Oregon, Washington, and back along the northern most states- Montana, Wyoming and the Dakotas, before heading back south and east. Everyone was super excited about this trip. Neither Amy nor I had ever been to that part of the country before.

We didn’t have the smoothest of starts to this trip. The evening before leaving, as I went to hitch up the truck, the tongue jack wouldn’t lift the trailer high enough to clear the ball hitch on the truck. I scrambled to the Tractor Supply store to get a tongue jack that, though it does the job, isn’t quite what you want for a travel trailer. With some help from my brother-in-law Rob and a little luck we got the new tongue jack put on and we managed to leave on time (almost). In hindsight, that seems to be a foreshadow of things to come. There were definitely more maintenance issues on this trip than the last!

13240706_10209884805302646_1537830871853160198_n

13260042_1237116412972969_1181387907238324022_n

13227123_10206257585906553_7109878245391875814_n

Just like last time, there would be a mix of travel days, sight seeing days, work/school days, and sometimes combinations of those. It didn’t take us long to get back into a rhythm once we were on the road. We wanted to stop and see some family in NC, TN and MO on the way out west, so that was the focus of our first few stops. Here are the stops we made on the way out west:

May 17-18 – Lexington NC – We stopped here to see Amy’s stepmother Gale. We spent a nice day at the house visiting. We went out for a meal at a nice restaurant. It was good to catch up.

May 19 – Newport TN – This was just an overnight stop in the mountains on the way towards Nashville. On our last trip we actually went down to Atlanta and then back up to Nashville just to avoid the mountains, but I figured that after 8000 miles or so of pulling that trailer I’d be OK. Besides, we’d have to go through the Rockies!

The campground was one of my favorites… definitely somewhere we could have spent more time. Pictured below is Jamie cooking up our supper! I think we were having cheeseburgers.

13256526_1238711209480156_5296327745995633224_n

May 20-23 – Nashville TN – My dad’s side of the family are in the middle TN area so seeing family was definitely the primary agenda in Nashville. We managed to see my grandmother, sisters Fallon and Hillary along with their kids, as well as my aunt Carla. We also squeezed in a trip to the Parthenon.

nashville_family

parthenon_kids

parthenon

May 24-26 – Bowling Green KY – Bowling Green is the home of the famous Mammoth Cave. Carlsbad Caverns was one of my personal highlights of the last trip so I was really looking forward to this. There are around 400 miles of caves in this system! Of course only a small portion of that is open to the public.

We set out on a tour, and as we got just about to the bottom, in a fairly narrow “corridor,” the group suddenly stopped. We stayed in place for 20-30 minutes before a Park Ranger came through saying that “we have a situation, law enforcement might be coming behind you.” Wait, what!?! That’s all the information we had for several more minutes before we learned that someone had fallen, possibly dislocating a shoulder so they didn’t want to move them. Our tour guide said that was the first time in 17 years that tour had been stopped – we just hit the lucky day! So, we “backed out” of that cave, but they put us on another tour that technically wasn’t even open to the public just yet.

mammoth1

mammoth2

May 27-30 – St Louis MO – my mom and sister Amanda both live in southeast MO so they were able to come spend time with us over the (Memorial Day) weekend. Being a summer holiday weekend, the campground was very busy. We ended up with a pretty good spot though, on the back end of the campground overlooking a cemetery! (At least the neighbors were quiet!)

We arrived at the campground on a Friday afternoon. That Saturday my sister Amanda, her daughters Cheyenne and Leah, and my sister Hillary (from TN!) with her family came up to see us. We went to a kid’s museum in St Louis, and of course the Gateway Arch. The Arch was a neat experience. The elevator that goes to the top has these little “pods” that look like something out of a sci-fi movie. Each “pod” seats about 5 people. You get out at the top, walk across a breezeway of sorts (though it’s anything but breezy, it’s actually pretty hot and stuffy) that overlooks the city, then get back in the elevator to go back down. The architecture and engineering are pretty amazing.

stlous_site

gateway

arch_seat

stlouis_family

Shortly after that whole crew left us my mom came up and spent a night with us. We took a trip over to Grant’s Farm. The property was once own by Ulysses S. Grant and now owned by Anheuser-Busch.

20160530_104739

20160530_111654

20160530_123404

May 31-June 2 – Kansas City MO – The main thing we wanted to do in Kansas City was go to Union Station. Union Station is, well, a big ole train station full of shops and exhibits. When we walked through it was just about empty. It’s striking how tall the ceilings are. It’s truly a beautiful building. After walking through the building we walked through a pedestrian crossing over the tracks on our way to Jack Stacks Barbecue.

unionstation

union_trains

June 3-6 – Omaha NE – We were really looking forward to getting to Omaha to see our good friends from our San Diego days, the Phipps family. It’s been a long time since we’d seen them but you wouldn’t have known it, we just picked right up like we’d just seen them last week! Jason and Candice were very welcoming and hospitable. We ate a great meal with their family and thoroughly enjoyed the evening! We just hope it’s not another 10 or 15 years before we see them again!

One negative note about Omaha – we caught a flat on the trailer. The road going into Omaha was so bad and bumpy that we didn’t even know it! It wasn’t until we made a left turn about a mile from the KOA we were staying at that I saw the tire in the mirror. Unfortunately this wouldn’t be the last flat either.

phipps

flat

June 7 – North Platte NE – Just passing through here on the way to Denver!

June 8-10 – Denver CO – I was really looking forward to our stay in Denver – the Mile High City! We didn’t actually stay in Denver, but just west of Denver in Central City. Central City is in the Rockies and sits at about 8500 feet. The view was gorgeous! The campground in Central City was one of my favorites, but it was a challenge to get up to it. There were several switchbacks and sharp turns up some pretty steep climbs.

Before we left home Amy had already looked ahead for any opportunity to see the San Diego Padres play and this was it! They were playing the Rockies while we were in Denver, so naturally we went to the game. We (mostly Amy) were one of just a few rooting for the Padres, but they won!

13445300_10206105440581859_1126259278655662573_n

centralcity

baseball

rockies

June 11-12 Silt CO – After leaving Denver and continuing west we had to climb up to just about 11,000 feet in elevation. Trucks were having to go slow to avoid overheating (including us). At one point going down some elevation our brakes started smoking. It was a real balancing act keeping the truck slow enough to maintain control and not smoking the brakes.

One of our favorite activities of the entire trip was in Silt. We ziplined over the Colorado river! We also celebrated Father’s day in Silt by hiking along the river.

silt

co_river

June 13-14 – Vernal UT – AKA Dinoland! Vernal’s “claim to fame” is the dinosaur bones found in the area. We went to the National Park where they have a structure built onto a rock wall with bones still embedded into it. The theory is that there was a river in that area where the bones had collected. Pretty incredible place.

vernal

vernal2

June 15-20 – Salt Lake UT – On the way to SLC we came across the famous Bonneville Salt Flats. It’s literally a huge flat area of … salt. Many land speed records have been set here. It was pretty cool to just walk around on the salt. It was so bright that you had to squint.

Of course we also had to visit the Great Salt Lake. We took a short hike around a section of the lake, ate lunch and then ventured down onto the beach. The water in the Salt Lake is very warm, and obviously salty. Nothing lives in the lake except brine shrimp. Amy bottled some of the water, and several brine shrimp were in the bottle. Most died but one hung on for quite some time. She named him Fred. Sadly, Fred died just a few days ago in a sea monkey aquarium in our home in NC. He lived a pretty long and adventurous life for a brine shrimp!

saltflats

saltlake

June 21 – Winnemucca NV – the road between SLC and the west coast is long and barren! You can see in the picture below the sign that read “Next Gas 179 Miles” !! There was very little on that road and hardly any cell reception. It’s definitely not somewhere you’d want to breakdown! Thankfully we made it through without any trouble.

Every time I think of Winnemucca I also think of the Johnny Cash song “I’ve been everywhere.” We would play that song in the truck naming off the places we had been.

into-OR-gas

June 22-24 – Klamath Falls OR – Home of Crater Lake. Crater Lake is easily, without a doubt the most beautiful place I’ve ever seen. The lake sits on an “imploded” volcano, and the water is nearly 2000 feet deep. It’s the deepest lake in the US and the 9th deepest lake in the world. The depth of the water makes it an incredible blue. There is no “feed” into the water – it’s filled just off rain and snow runoff. This area get a LOT of snow – over 10 feet a year. We drove about half way around the lake, stopping at different points to look at the lake from another point of view (the road on the other half was still closed from snow!). I hope to return to this area again one day, it was truly stunning.

craterlake2

craterlake

That’s all for this installment. I’ll write about the rest of this trip in another post soon!

Posted in Travel | Leave a comment

Error Establishing Database Connection in WordPress

My website (and a couple others on the same server) had been plagued with this mysterious ‘Error Establishing Database Connection’ for several weeks. I actually thought I had exhausted the system resources of my small web server and probably needed to upgrade it (add more RAM). I hadn’t considered the possibility that something more devious was going on, but it turns out my WordPress installation was vulnerable and was being 0wned!

This particular attack utilized the XML-RPC capabilities of WordPress. RPC is short for ‘Remote Procedure Call’. It’s a mechanism to execute procedures on a remote computer as if you were running locally. It’s a pretty powerful mechanism, but can be fairly dangerous too.

There are a few fixes published on the Internet. One solution was to enable Jetpack‘s security features. I tried it and it didn’t work. What did work for me was a two fold strategy.

1. Use a firewall to specifically deny the IP addresses of the attackers. I would consider this the first line of defense — it works at the lowest possible level. The problem with the Jetpack solution is that it works at the application tier, which consumes more system resources, leaving you open to denial-of-service type attacks.

I’m running Apache on an Ubuntu server. To find the IP addresses of the attackers, I did something like this:


fgrep '"POST /xmlrpc.php HTTP/1.0" 500 585 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"' /var/log/apache2/access.log | cut -d' ' -f1 | sort | uniq

Once I had the IP addresses I installed Uncomplicated Firewall, and added a rule for each IP address.


sudo ufw insert 1 deny from 13.65.30.225
sudo ufw insert 1 deny from 13.66.57.205
sudo ufw insert 1 deny from 185.143.173.56

That alone helped dramatically, but doesn’t stop someone coming in from another address, so another step was needed.

2. I explicitly reject any web request for xmlrpc.php. You can do this using an .htaccess file, or directly in the web site configuration (in my case in /etc/apache2/sites-enabled). I added the following snippet to the bottom of the virtual host file(s). (I believe you could also do this globally if you didn’t want to do it per-site.)


<files xmlrpc.php>
order allow,deny
</files>

Note, this disabled XML-RPC and therefore any features/plugins that require it! However, it works fine for my purposes. YMMV!

Posted in IT | Leave a comment

vprintf segfault on Ubuntu Linux 15.10

I have a C program with a ‘print’ function that accepts a format string and variable list of arguments, similar to printf style functions. The function simply prints to stdout and also to a logfile.

void print(const char* format, ...) {
	pthread_mutex_lock(&logfile_mutex);
 
	va_list args;
	va_start(args,format);
 
	vprintf(format,args);
	fflush(stdout);
 
	fprintf(logfile,"%d ",milli_timer());
	vfprintf(logfile,format,args);
	fflush(logfile);
 
	va_end(args);
 
	pthread_mutex_unlock(&logfile_mutex);
}

Everything seemed fine compiling with g++ under Cygwin, but would crash when compiled on Ubuntu Linux 15.10. After a bit of digging I finally spotted the problem in the documentation for vprintf:

Internally, the function retrieves arguments from the list identified by arg as if va_arg was used on it, and thus the state of arg is likely altered by the call.

Apparently this is one of those things that is compiler specific. Since we can’t rely on the state of the arguments list after the first call to vprintf, the solution was simply to use a new arguments list for the second call to vprintf which writes to the log file. Revised function:

void print(const char* format, ...) {
	pthread_mutex_lock(&logfile_mutex);
 
	va_list stdout_args;
	va_start(stdout_args,format);
	vprintf(format,stdout_args);
	fflush(stdout);
	va_end(stdout_args);
 
	va_list log_args;
	va_start(log_args,format);
	fprintf(logfile,"%d ",milli_timer());
	vfprintf(logfile,format,log_args);
	fflush(logfile);
	va_end(log_args);
 
	pthread_mutex_unlock(&logfile_mutex);
}

Hope that helps someone.

Posted in Software Development | Leave a comment

local array causes segfault

Recently while working on a C program I was intermittently getting a segfault. The code appeared correct yet it would inexplicably crash, seemingly at random. I compiled the program with the ‘-g’ flag to enable debugging symbols, and discovered I was dealing with the dreaded stack overflow.


Exception: STATUS_STACK_OVERFLOW at rip=00100414BC6

The line of code in question was the declaration of a large local array. Something like:


int foo[REALLY_BIG_NUMBER];

The fix was really simple. I just replaced that line of code with this one:


int* foo = malloc(REALLY_BIG_NUMBER * sizeof(int));
...
// later on...
free(foo); // <--- very important!

That's it. The difference is the area of memory that the data is allocated in. In the former example (the local array), the compiler used stack memory. The stack is an area of memory used for temporary variables created by each function. By allocating a large array, I tried to fit more into the stack than it could accommodate, hence the 'stack overflow'. In the latter example, a different area of memory is used called the heap. The heap is not as tightly managed and is somewhat larger.

Posted in Software Development | Leave a comment