File: setnewhandler.cpp

package info (click to toggle)
muscle 3.70%2Bfix1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,424 kB
  • ctags: 2,116
  • sloc: cpp: 26,897; xml: 230; makefile: 25
file content (26 lines) | stat: -rw-r--r-- 612 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "muscle.h"
#include <stdio.h>
#include <new>

const int ONE_MB = 1024*1024;
const size_t RESERVE_BYTES = 8*ONE_MB;
static void *EmergencyReserve = 0;

void OnOutOfMemory()
	{
	free(EmergencyReserve);
	fprintf(stderr, "\n*** OUT OF MEMORY ***\n");
	fprintf(stderr, "Memory allocated so far %g MB\n", GetMemUseMB());
	extern MSA *ptrBestMSA;
	if (ptrBestMSA == 0)
		fprintf(stderr, "No alignment generated\n");
	else
		SaveCurrentAlignment();
	exit(EXIT_FatalError);
	}

void SetNewHandler()
	{
	EmergencyReserve = malloc(RESERVE_BYTES);
	std::set_new_handler(OnOutOfMemory);
	}