Ejemplo n.º 1
0
pointer CGAlloc( size_t size )
/****************************/
{
    pointer     chunk;

    _MemLow;
    for( ;; ) {
#if _MEMORY_TRACKING & _FULL_TRACKING
        chunk = _trmem_alloc( size, _trmem_guess_who(), Handle );
#else
        chunk = _SysAlloc( size );
#endif
        if( chunk != NULL ) {
#if _MEMORY_TRACKING & _CHUNK_TRACKING
            ++Chunks;
#endif
            _AlignmentCheck( chunk, 8 );
            return( chunk );
        }
        if( !_MemCheck( size ) ) {
            break;
        }
    }
    if( ( MemOut == MO_FATAL ) || ( InOptimizer != 0 ) ) {
        FatalError( "Out of memory" );
    } else if( MemOut == MO_SUICIDE ) {
        Suicide();
    }
    return( NULL );
}
Ejemplo n.º 2
0
void tracer::log(const char* format ...)
{
	static FILE* logFile;
	static int entryCount;

	entryCount++;

	if (tracingIsOn)
		{
		#if defined(DEBUG)		
		// handle the fact that _MemCheck() calls trace functions
		if (entryCount == 1)
			{
			_MemCheck();
			}
		#endif

		if (!logFile)
			{
			logFile = fopen("trace.log", "wt");
			time_t	t;

			time(&t);

			fprintf(logFile, "Started %s", ctime(&t));
			}

		for (int i=0; i < indent; i++)
			fprintf(logFile, "\t");

#if defined(__GNUG__)
		if (strrchr(fileName, '/'))
			fprintf(logFile, "%14s %4i: ", strrchr(fileName, '/')+1, lineNo);
		else
			fprintf(logFile, "%14s %4i: ", fileName, lineNo);
#else
		if (strrchr(fileName, '\\'))
			fprintf(logFile, "%14s %4i: ", strrchr(fileName, '\\')+1, lineNo);
		else
			fprintf(logFile, "%14s %4i: ", fileName, lineNo);
#endif

		va_list	ap;

		va_start(ap, format);

		vfprintf(logFile, format, ap);
		fprintf(logFile, "\n");
		fflush(logFile);
		// logFile = fopen("trace.log", "at");

		va_end(ap);
		}

	entryCount--;
}