Esempio n. 1
0
void *Hunk_HighAllocName (int size, char *name) {
    hunk_t *h;

    if (size < 0)
        Sys_Error ("Hunk_HighAllocName: bad size: %i", size);

    if (hunk_tempactive) {
        Hunk_FreeToHighMark (hunk_tempmark);
        hunk_tempactive = false;
    }

#ifdef PARANOID
    Hunk_Check ();
#endif

    size = sizeof(hunk_t) + ((size+15)&~15);

    if (hunk_size - hunk_low_used - hunk_high_used < size)
        Sys_Error ("Hunk_HighAllocName: Not enough RAM allocated.  Try using \"-mem 128\" on the ezQuake command line.");

    hunk_high_used += size;
    Cache_FreeHigh (hunk_high_used);

    h = (hunk_t *) (hunk_base + hunk_size - hunk_high_used);

    memset (h, 0, size);
    h->size = size;
    h->sentinal = HUNK_SENTINEL;
    strlcpy (h->name, name, sizeof (h->name));

    return (void *) (h + 1);
}
Esempio n. 2
0
int	Hunk_HighMark (void) {
    if (hunk_tempactive) {
        hunk_tempactive = false;
        Hunk_FreeToHighMark (hunk_tempmark);
    }
    return hunk_high_used;
}
Esempio n. 3
0
void Hunk_FreeToHighMark (int mark) {
    if (hunk_tempactive) {
        hunk_tempactive = false;
        Hunk_FreeToHighMark (hunk_tempmark);
    }
    if (mark < 0 || mark > hunk_high_used)
        Sys_Error ("Hunk_FreeToHighMark: bad mark %i", mark);
    memset (hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
    hunk_high_used = mark;
}
Esempio n. 4
0
//Return space from the top of the hunk
void *Hunk_TempAlloc (int size) {
    void *buf;

    size = (size + 15) & ~15;

    if (hunk_tempactive) {
        Hunk_FreeToHighMark (hunk_tempmark);
        hunk_tempactive = false;
    }

    hunk_tempmark = Hunk_HighMark ();

    buf = Hunk_HighAllocName (size, "temp");

    hunk_tempactive = true;

    return buf;
}
Esempio n. 5
0
void Hunk_FreeToHighMark (int mark)
{
	if (hunk_tempactive)
	{
		hunk_tempactive = false;
		Hunk_FreeToHighMark (hunk_tempmark);
	}
	if (mark < 0 || mark > hunk_high_used)
		Sys_Error ("Hunk_FreeToHighMark: bad mark %i", mark);

#if 0
	memset (hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
#else
	// Fill the memory with junk (debug only) or don't bother in non-debug
	#if _DEBUG
	memset (hunk_base + hunk_size - hunk_high_used, 0xDD, hunk_high_used - mark);
	#endif
#endif
	hunk_high_used = mark;
}
Esempio n. 6
0
/*
================
VID_AllocBuffers
================
*/
static qboolean VID_AllocBuffers (int width, int height)
{
	int		tsize, tbuffersize;

	tbuffersize = width * height * sizeof (*d_pzbuffer);

	tsize = D_SurfaceCacheForRes (width, height);

	tbuffersize += tsize;

// see if there's enough memory, allowing for the normal mode 0x13 pixel,
// z, and surface buffers
	//if ((host_parms->memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
	//	 0x10000 * 3) < MINIMUM_MEMORY)
	// Pa3PyX: using hopefully better estimation now
	// if total memory < needed surface cache + (minimum operational memory
	// less surface cache for 320x200 and typical hunk state after init)
	if (host_parms->memsize < tbuffersize + 0x180000 + 0xC00000)
	{
		Con_SafePrintf ("Not enough memory for video mode\n");
		return false;		// not enough memory for mode
	}

	vid_surfcachesize = tsize;

	if (d_pzbuffer)
	{
		D_FlushCaches ();
		Hunk_FreeToHighMark (VID_highhunkmark);
		d_pzbuffer = NULL;
	}

	VID_highhunkmark = Hunk_HighMark ();

	d_pzbuffer = (short *) Hunk_HighAllocName (tbuffersize, "video");

	vid_surfcache = (byte *)d_pzbuffer +
			width * height * sizeof (*d_pzbuffer);
	
	return true;
}
Esempio n. 7
0
File: zone.cpp Progetto: m4c0/Quake
/*
===================
Hunk_HighAllocName
===================
*/
void *Hunk_HighAllocName (int size, const char *name)
{
	hunk_t	*h;

	if (size < 0)
		Sys_Error ("Hunk_HighAllocName: bad size: %i", size);

	if (hunk_tempactive)
	{
		Hunk_FreeToHighMark (hunk_tempmark);
		hunk_tempactive = false;
	}

#ifdef PARANOID
	Hunk_Check ();
#endif

	size = sizeof(hunk_t) + ((size+15)&~15);

	if (hunk_size - hunk_low_used - hunk_high_used < size)
	{
		Con_Printf ("Hunk_HighAlloc: failed on %i bytes\n",size);
		return NULL;
	}

	hunk_high_used += size;
	Cache_FreeHigh (hunk_high_used);

	h = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);

	memset (h, 0, size);
	h->size = size;
	h->sentinal = HUNK_SENTINAL;
	strncpy (h->name, name, 8);

	return (void *)(h+1);
}