On Wed, 04 Sep 2013 19:45:44 +0200, Sönke Ludwig wrote:

Am 04.09.2013 17:39, schrieb Craig Dillabaugh:

So I have identified the line of code causing the error, but I am no less perplexed than before.

It is the line:

	ubyte[tile_size * tile_size] data;

If tile_size >= 246 (total 60516 bytes) then the program crashes with error code -11, otherwise it seems to run fine.
Since this is a static array, and D has a limit on static array sizes, I thought that might be the problem, but D allows static arrays of size up to 16Mb, and this is clearly much smaller. Also, it should have generated a compile time error.

Is it perhaps a fiber problem. Maybe fibers don't allow such large static data structures? Any ideas?

I see, the problem is that the stack size of fibers is kept relatively
small to save on virtual address space on 32-bit systems. It can be
enlarged using vibe.core.core.setTaskStackSize.

However, I would strongly recommend to replace the section of the code with:

try {
	auto file = openFile(filename, FileMode.read);
	res.bodyWriter.write(file);
}

That will avoid having to buffer the whole file in memory and will avoid
potentially blocking the event loop for a long while (and thus blocking
any other parallel requests).

To improve it further, res.writeRawBody could be used (this will use
DMA to transfer directly from disk to network if possible), but in that
case care needs to be taken to set the right HTTP headers. Maybe it
actually makes sense to make vibe.http.fileserver.sendFile public and
use that...

Great. I will try your suggested improvement. It certainly makes more sense than reading the whole thing into memory.