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
/*
 * =====================
 * Hunk_TempAllocExtend
 *
 * Extend the existing temp hunk allocation.
 * Size is the number of extra bytes required
 * =====================
 */
void *
Hunk_TempAllocExtend(int size)
{
    hunk_t *old, *newobj;

    if (!hunk_tempactive)
	Sys_Error("%s: temp hunk not active", __func__);

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

    if (old->sentinal != HUNK_SENTINAL)
	Sys_Error("%s: old sentinal trashed\n", __func__);
    if (strncmp(old->name, "temp", HUNK_NAMELEN))
	Sys_Error("%s: old hunk name trashed\n", __func__);

    size = (size + 15) & ~15;
    if (hunk_size - hunk_low_used - hunk_high_used < size) {
	Con_Printf("%s: failed on %i bytes\n", __func__, size);
	return NULL;
    }

    hunk_high_used += size;
    Cache_FreeHigh(hunk_high_used);

    newobj = (hunk_t *)(hunk_base + hunk_size - hunk_high_used);
    memmove(newobj, old, sizeof(hunk_t));
    newobj->size += size;

    return (void *)(newobj + 1);
}
Esempio n. 3
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);
}