mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-29 07:32:02 +00:00
[util] Make hunk (optionally) thread-safe
For now, the functions check for a null hunk pointer and use the global hunk (initialized via Memory_Init) if necessary. However, Hunk_Init is available (and used by Memory_Init) to create a hunk from any arbitrary memory block. So long as that block is 64-byte aligned, allocations within the hunk will remain 64-byte aligned.
This commit is contained in:
parent
8fdd9c1f5a
commit
54604d9aa2
51 changed files with 375 additions and 295 deletions
|
@ -106,13 +106,16 @@ void Z_SetError (memzone_t *zone, void (*err) (void *data, const char *msg),
|
|||
void *data);
|
||||
void Z_CheckPointer (const memzone_t *zone, const void *ptr, size_t size);
|
||||
|
||||
void Hunk_Print (qboolean all);
|
||||
void *Hunk_Alloc (size_t size); // returns 0 filled memory
|
||||
void *Hunk_AllocName (size_t size, const char *name);
|
||||
size_t Hunk_LowMark (void) __attribute__((pure));
|
||||
void Hunk_FreeToLowMark (size_t mark);
|
||||
void *Hunk_TempAlloc (size_t size);
|
||||
void Hunk_Check (void);
|
||||
typedef struct memhunk_s memhunk_t;
|
||||
|
||||
memhunk_t *Hunk_Init (void *buf, size_t size);
|
||||
void Hunk_Print (memhunk_t *hunk, qboolean all);
|
||||
void Hunk_Check (memhunk_t *hunk);
|
||||
void *Hunk_Alloc (memhunk_t *hunk, size_t size); // returns 0 filled memory
|
||||
void *Hunk_AllocName (memhunk_t *hunk, size_t size, const char *name);
|
||||
size_t Hunk_LowMark (memhunk_t *hunk) __attribute__((pure));
|
||||
void Hunk_FreeToLowMark (memhunk_t *hunk, size_t mark);
|
||||
void *Hunk_TempAlloc (memhunk_t *hunk, size_t size);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ load_file (progs_t *pr, const char *path, off_t *size)
|
|||
static void *
|
||||
allocate_progs_mem (progs_t *pr, int size)
|
||||
{
|
||||
return Hunk_AllocName (size, pr->progs_name);
|
||||
return Hunk_AllocName (0, size, pr->progs_name);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -69,7 +69,7 @@ GIB_Exec_Override_f (void)
|
|||
return;
|
||||
}
|
||||
|
||||
mark = Hunk_LowMark ();
|
||||
mark = Hunk_LowMark (0);
|
||||
f = (char *) QFS_LoadHunkFile (QFS_FOpenFile (Cmd_Argv (1)));
|
||||
if (!f) {
|
||||
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
||||
|
@ -95,7 +95,7 @@ GIB_Exec_Override_f (void)
|
|||
Cmd_Argv (0), Cmd_Argv (1));
|
||||
} else
|
||||
Cbuf_InsertText (cbuf_active, f);
|
||||
Hunk_FreeToLowMark (mark);
|
||||
Hunk_FreeToLowMark (0, mark);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
|
|
|
@ -64,8 +64,8 @@ LoadPCX (QFile *f, qboolean convert, const byte *pal, int load)
|
|||
fsize = Qfilesize(f);
|
||||
}
|
||||
// parse the PCX file
|
||||
pcx_mark = Hunk_LowMark ();
|
||||
pcx = Hunk_AllocName (fsize, "PCX");
|
||||
pcx_mark = Hunk_LowMark (0);
|
||||
pcx = Hunk_AllocName (0, fsize, "PCX");
|
||||
Qread (f, pcx, fsize);
|
||||
|
||||
pcx->xmax = LittleShort (pcx->xmax);
|
||||
|
@ -84,7 +84,7 @@ LoadPCX (QFile *f, qboolean convert, const byte *pal, int load)
|
|||
Sys_Printf ("Bad pcx file: %x %d %d %d\n",
|
||||
pcx->manufacturer, pcx->version, pcx->encoding,
|
||||
pcx->bits_per_pixel);
|
||||
Hunk_FreeToLowMark (pcx_mark);
|
||||
Hunk_FreeToLowMark (0, pcx_mark);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,12 @@ LoadPCX (QFile *f, qboolean convert, const byte *pal, int load)
|
|||
|
||||
count = load ? (pcx->xmax + 1) * (pcx->ymax + 1) : 0;
|
||||
if (convert) {
|
||||
tex = Hunk_TempAlloc (sizeof (tex_t) + count * 3);
|
||||
tex = Hunk_TempAlloc (0, sizeof (tex_t) + count * 3);
|
||||
tex->data = (byte *) (tex + 1);
|
||||
tex->format = tex_rgb;
|
||||
tex->palette = 0;
|
||||
} else {
|
||||
tex = Hunk_TempAlloc (sizeof (tex_t) + count);
|
||||
tex = Hunk_TempAlloc (0, sizeof (tex_t) + count);
|
||||
tex->data = (byte *) (tex + 1);
|
||||
tex->format = tex_palette;
|
||||
if (pal)
|
||||
|
@ -110,7 +110,7 @@ LoadPCX (QFile *f, qboolean convert, const byte *pal, int load)
|
|||
tex->height = pcx->ymax + 1;
|
||||
tex->loaded = load;
|
||||
if (!load) {
|
||||
Hunk_FreeToLowMark (pcx_mark);
|
||||
Hunk_FreeToLowMark (0, pcx_mark);
|
||||
return tex;
|
||||
}
|
||||
pix = tex->data;
|
||||
|
@ -144,7 +144,7 @@ LoadPCX (QFile *f, qboolean convert, const byte *pal, int load)
|
|||
}
|
||||
dataByte++;
|
||||
}
|
||||
Hunk_FreeToLowMark (pcx_mark);
|
||||
Hunk_FreeToLowMark (0, pcx_mark);
|
||||
if (count || runLength) {
|
||||
Sys_Printf ("PCX was malformed. You should delete it.\n");
|
||||
return 0;
|
||||
|
@ -162,7 +162,7 @@ EncodePCX (const byte *data, int width, int height,
|
|||
const byte *dataend;
|
||||
|
||||
size = width * height * 2 + 1000;
|
||||
if (!(pcx = Hunk_TempAlloc (size))) {
|
||||
if (!(pcx = Hunk_TempAlloc (0, size))) {
|
||||
Sys_Printf ("EncodePCX: not enough memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -162,10 +162,10 @@ LoadPNG (QFile *infile, int load)
|
|||
|
||||
/* Allocate tex_t structure */
|
||||
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
tex = Hunk_TempAlloc (sizeof (tex_t) + height * rowbytes);
|
||||
tex = Hunk_TempAlloc (0, sizeof (tex_t) + height * rowbytes);
|
||||
tex->data = (byte *) (tex + 1);
|
||||
} else {
|
||||
tex = Hunk_TempAlloc (sizeof (tex_t));
|
||||
tex = Hunk_TempAlloc (0, sizeof (tex_t));
|
||||
tex->data = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ parse_colormap (TargaHeader *targa, byte **dataByte)
|
|||
case 24:
|
||||
case 16:
|
||||
case 15:
|
||||
cmap = Hunk_AllocName (256 * sizeof (cmap_t), "TGA cmap");
|
||||
cmap = Hunk_AllocName (0, 256 * sizeof (cmap_t), "TGA cmap");
|
||||
break;
|
||||
default:
|
||||
Sys_Error ("LoadTGA: unsupported color map size");
|
||||
|
@ -632,8 +632,8 @@ LoadTGA (QFile *fin, int load)
|
|||
if (load) {
|
||||
fsize = Qfilesize (fin);
|
||||
}
|
||||
targa_mark = Hunk_LowMark ();
|
||||
targa = Hunk_AllocName (fsize, "TGA");
|
||||
targa_mark = Hunk_LowMark (0);
|
||||
targa = Hunk_AllocName (0, fsize, "TGA");
|
||||
Qread (fin, targa, fsize);
|
||||
|
||||
targa->colormap_index = LittleShort (targa->colormap_index);
|
||||
|
@ -646,7 +646,7 @@ LoadTGA (QFile *fin, int load)
|
|||
if (targa->image_type >= NUM_DECODERS
|
||||
|| !(decode = decoder_functions[targa->image_type])) {
|
||||
Sys_Printf ("LoadTGA: Unsupported targa type");
|
||||
Hunk_FreeToLowMark (targa_mark);
|
||||
Hunk_FreeToLowMark (0, targa_mark);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -655,7 +655,7 @@ LoadTGA (QFile *fin, int load)
|
|||
} else {
|
||||
numPixels = 0;
|
||||
}
|
||||
tex = Hunk_TempAlloc (sizeof (tex_t) + numPixels * 4);
|
||||
tex = Hunk_TempAlloc (0, sizeof (tex_t) + numPixels * 4);
|
||||
tex->data = (byte *) (tex + 1);
|
||||
tex->width = targa->width;
|
||||
tex->height = targa->height;
|
||||
|
@ -670,7 +670,7 @@ LoadTGA (QFile *fin, int load)
|
|||
decode (targa, tex, dataByte);
|
||||
}
|
||||
|
||||
Hunk_FreeToLowMark (targa_mark);
|
||||
Hunk_FreeToLowMark (0, targa_mark);
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
|
|
@ -475,7 +475,7 @@ gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
|||
// save the data out
|
||||
header->poseverts = numorder;
|
||||
|
||||
cmds = Hunk_Alloc (numcommands * sizeof (int));
|
||||
cmds = Hunk_Alloc (0, numcommands * sizeof (int));
|
||||
header->commands = (byte *) cmds - (byte *) header;
|
||||
memcpy (cmds, commands, numcommands * sizeof (int));
|
||||
|
||||
|
@ -490,7 +490,7 @@ gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
|||
}
|
||||
header->poseverts = numorder;
|
||||
|
||||
tex_coord = Hunk_Alloc (numorder * sizeof(tex_coord_t));
|
||||
tex_coord = Hunk_Alloc (0, numorder * sizeof(tex_coord_t));
|
||||
header->tex_coord = (byte *) tex_coord - (byte *) header;
|
||||
for (i=0; i < numorder; i++) {
|
||||
float s, t;
|
||||
|
@ -510,7 +510,7 @@ gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
|||
|
||||
if (extra) {
|
||||
trivertx16_t *verts;
|
||||
verts = Hunk_Alloc (header->numposes * header->poseverts
|
||||
verts = Hunk_Alloc (0, header->numposes * header->poseverts
|
||||
* sizeof (trivertx16_t));
|
||||
header->posedata = (byte *) verts - (byte *) header;
|
||||
for (i = 0; i < header->numposes; i++) {
|
||||
|
@ -532,7 +532,7 @@ gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
|||
}
|
||||
} else {
|
||||
trivertx_t *verts;
|
||||
verts = Hunk_Alloc (header->numposes * header->poseverts
|
||||
verts = Hunk_Alloc (0, header->numposes * header->poseverts
|
||||
* sizeof (trivertx_t));
|
||||
header->posedata = (byte *) verts - (byte *) header;
|
||||
for (i = 0; i < header->numposes; i++) {
|
||||
|
|
|
@ -63,7 +63,7 @@ gl_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
|
|||
int fb_texnum = 0, texnum = 0;
|
||||
dstring_t *name = dstring_new ();
|
||||
|
||||
pskin = Hunk_AllocName (skinsize, alias_ctx->mod->name);
|
||||
pskin = Hunk_AllocName (0, skinsize, alias_ctx->mod->name);
|
||||
skindesc->skin = (byte *) pskin - (byte *) header;
|
||||
|
||||
memcpy (pskin, skin, skinsize);
|
||||
|
|
|
@ -66,7 +66,7 @@ Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx, int numskins,
|
|||
Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d", numskins);
|
||||
|
||||
skinsize = header->mdl.skinwidth * header->mdl.skinheight;
|
||||
pskindesc = Hunk_AllocName (numskins * sizeof (maliasskindesc_t),
|
||||
pskindesc = Hunk_AllocName (0, numskins * sizeof (maliasskindesc_t),
|
||||
alias_ctx->mod->name);
|
||||
|
||||
*pskinindex = (byte *) pskindesc - (byte *) header;
|
||||
|
@ -83,13 +83,13 @@ Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx, int numskins,
|
|||
groupskins = LittleLong (pinskingroup->numskins);
|
||||
|
||||
t = field_offset (maliasskingroup_t, skindescs[groupskins]);
|
||||
paliasskingroup = Hunk_AllocName (t, alias_ctx->mod->name);
|
||||
paliasskingroup = Hunk_AllocName (0, t, alias_ctx->mod->name);
|
||||
paliasskingroup->numskins = groupskins;
|
||||
|
||||
pskindesc[snum].skin = (byte *) paliasskingroup - (byte *) header;
|
||||
|
||||
pinskinintervals = (daliasskininterval_t *) (pinskingroup + 1);
|
||||
poutskinintervals = Hunk_AllocName (groupskins * sizeof (float),
|
||||
poutskinintervals = Hunk_AllocName (0, groupskins * sizeof (float),
|
||||
alias_ctx->mod->name);
|
||||
paliasskingroup->intervals =
|
||||
(byte *) poutskinintervals - (byte *) header;
|
||||
|
@ -173,8 +173,9 @@ Mod_LoadAliasGroup (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum,
|
|||
frame->firstpose = (*posenum);
|
||||
frame->numposes = numframes;
|
||||
|
||||
paliasgroup = Hunk_AllocName (field_offset (maliasgroup_t,
|
||||
frames[numframes]), mod->name);
|
||||
paliasgroup = Hunk_AllocName (0, field_offset (maliasgroup_t,
|
||||
frames[numframes]),
|
||||
mod->name);
|
||||
paliasgroup->numframes = numframes;
|
||||
frame->frame = (byte *) paliasgroup - (byte *) header;
|
||||
|
||||
|
@ -187,7 +188,7 @@ Mod_LoadAliasGroup (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum,
|
|||
alias_ctx->aliasbboxmaxs);
|
||||
|
||||
pin_intervals = (daliasinterval_t *) (pingroup + 1);
|
||||
poutintervals = Hunk_AllocName (numframes * sizeof (float), mod->name);
|
||||
poutintervals = Hunk_AllocName (0, numframes * sizeof (float), mod->name);
|
||||
paliasgroup->intervals = (byte *) poutintervals - (byte *) header;
|
||||
frame->interval = LittleFloat (pin_intervals->interval);
|
||||
for (i = 0; i < numframes; i++) {
|
||||
|
@ -237,7 +238,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
|
|||
CRC_Init (&crc);
|
||||
CRC_ProcessBlock (buffer, &crc, qfs_filesize);
|
||||
|
||||
start = Hunk_LowMark ();
|
||||
start = Hunk_LowMark (0);
|
||||
|
||||
pinmodel = (mdl_t *) buffer;
|
||||
|
||||
|
@ -249,7 +250,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
|
|||
// allocate space for a working header, plus all the data except the
|
||||
// frames, skin and group info
|
||||
size = field_offset (aliashdr_t, frames[LittleLong (pinmodel->numframes)]);
|
||||
header = Hunk_AllocName (size, mod->name);
|
||||
header = Hunk_AllocName (0, size, mod->name);
|
||||
memset (header, 0, size);
|
||||
alias_ctx.header = header;
|
||||
pmodel = &header->mdl;
|
||||
|
@ -375,14 +376,14 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
|
|||
|
||||
// move the complete, relocatable alias model to the cache
|
||||
if (m_funcs->alias_cache) {
|
||||
end = Hunk_LowMark ();
|
||||
end = Hunk_LowMark (0);
|
||||
total = end - start;
|
||||
|
||||
mem = allocator (&mod->cache, total, mod->name);
|
||||
if (mem)
|
||||
memcpy (mem, header, total);
|
||||
|
||||
Hunk_FreeToLowMark (start);
|
||||
Hunk_FreeToLowMark (0, start);
|
||||
mod->aliashdr = 0;
|
||||
} else {
|
||||
mod->aliashdr = header;
|
||||
|
|
|
@ -56,7 +56,7 @@ sw_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin,
|
|||
{
|
||||
byte *pskin;
|
||||
|
||||
pskin = Hunk_AllocName (skinsize, alias_ctx->mod->name);
|
||||
pskin = Hunk_AllocName (0, skinsize, alias_ctx->mod->name);
|
||||
skindesc->skin = (byte *) pskin - (byte *) alias_ctx->header;
|
||||
|
||||
memcpy (pskin, skin, skinsize);
|
||||
|
@ -75,7 +75,7 @@ process_frame (mod_alias_ctx_t *alias_ctx, maliasframedesc_t *frame,
|
|||
if (extra)
|
||||
size *= 2;
|
||||
|
||||
frame_verts = Hunk_AllocName (size, alias_ctx->mod->name);
|
||||
frame_verts = Hunk_AllocName (0, size, alias_ctx->mod->name);
|
||||
frame->frame = (byte *) frame_verts - (byte *) header;
|
||||
|
||||
// The low-order 8 bits (actually, fractional) are completely separate
|
||||
|
@ -96,9 +96,9 @@ sw_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
|||
stvert_t *stverts;
|
||||
mtriangle_t *tris;
|
||||
|
||||
stverts = (stvert_t *) Hunk_AllocName (numv * sizeof (stvert_t),
|
||||
stverts = (stvert_t *) Hunk_AllocName (0, numv * sizeof (stvert_t),
|
||||
alias_ctx->mod->name);
|
||||
tris = (mtriangle_t *) Hunk_AllocName (numt * sizeof (mtriangle_t),
|
||||
tris = (mtriangle_t *) Hunk_AllocName (0, numt * sizeof (mtriangle_t),
|
||||
alias_ctx->mod->name);
|
||||
|
||||
header->stverts = (byte *) stverts - (byte *) header;
|
||||
|
|
|
@ -121,7 +121,7 @@ Vulkan_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skinpix, int skinsize,
|
|||
byte *tskin;
|
||||
int w, h;
|
||||
|
||||
skin = Hunk_Alloc (sizeof (qfv_alias_skin_t));
|
||||
skin = Hunk_Alloc (0, sizeof (qfv_alias_skin_t));
|
||||
QuatCopy (vid.palette32 + (TOP_RANGE + 15) * 4, skin->colora);
|
||||
QuatCopy (vid.palette32 + (BOTTOM_RANGE + 15) * 4, skin->colorb);
|
||||
skindesc->skin = (byte *) skin - (byte *) header;
|
||||
|
@ -449,7 +449,7 @@ Vulkan_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
|||
QFV_PacketSubmit (packet);
|
||||
QFV_DestroyStagingBuffer (stage);
|
||||
|
||||
qfv_alias_mesh_t *mesh = Hunk_Alloc (sizeof (qfv_alias_mesh_t));
|
||||
qfv_alias_mesh_t *mesh = Hunk_Alloc (0, sizeof (qfv_alias_mesh_t));
|
||||
mesh->vertex_buffer = vbuff;
|
||||
mesh->uv_buffer = uvbuff;
|
||||
mesh->index_buffer = ibuff;
|
||||
|
|
|
@ -181,7 +181,8 @@ gl_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
|
|||
dstring_delete (litfilename);
|
||||
return;
|
||||
}
|
||||
brush->lightdata = Hunk_AllocName (bsp->lightdatasize * mod_lightmap_bytes,
|
||||
brush->lightdata = Hunk_AllocName (0,
|
||||
bsp->lightdatasize * mod_lightmap_bytes,
|
||||
litfilename->str);
|
||||
in = bsp->lightdata;
|
||||
out = brush->lightdata;
|
||||
|
@ -283,7 +284,7 @@ SubdividePolygon (int numverts, float *verts)
|
|||
return;
|
||||
}
|
||||
|
||||
poly = Hunk_Alloc (sizeof (glpoly_t) + (numverts - 4) * VERTEXSIZE *
|
||||
poly = Hunk_Alloc (0, sizeof (glpoly_t) + (numverts - 4) * VERTEXSIZE *
|
||||
sizeof (float));
|
||||
poly->next = warpface->polys;
|
||||
warpface->polys = poly;
|
||||
|
|
|
@ -156,6 +156,6 @@ glsl_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
|
|||
mod->brush.lightdata = NULL;
|
||||
return;
|
||||
}
|
||||
mod->brush.lightdata = Hunk_AllocName (bsp->lightdatasize, mod->name);
|
||||
mod->brush.lightdata = Hunk_AllocName (0, bsp->lightdatasize, mod->name);
|
||||
memcpy (mod->brush.lightdata, bsp->lightdata, bsp->lightdatasize);
|
||||
}
|
||||
|
|
|
@ -260,7 +260,8 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
|
|||
m = (dmiptexlump_t *) bsp->texdata;
|
||||
|
||||
brush->numtextures = m->nummiptex;
|
||||
brush->textures = Hunk_AllocName (m->nummiptex * sizeof (*brush->textures),
|
||||
brush->textures = Hunk_AllocName (0,
|
||||
m->nummiptex * sizeof (*brush->textures),
|
||||
mod->name);
|
||||
|
||||
for (i = 0; i < m->nummiptex; i++) {
|
||||
|
@ -275,7 +276,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
|
|||
if ((mt->width & 15) || (mt->height & 15))
|
||||
Sys_Error ("Texture %s is not 16 aligned", mt->name);
|
||||
pixels = mt->width * mt->height / 64 * 85;
|
||||
tx = Hunk_AllocName (sizeof (texture_t) + pixels, mod->name);
|
||||
tx = Hunk_AllocName (0, sizeof (texture_t) + pixels, mod->name);
|
||||
|
||||
brush->textures[i] = tx;
|
||||
|
||||
|
@ -296,7 +297,7 @@ Mod_LoadTextures (model_t *mod, bsp_t *bsp)
|
|||
size_t render_size = mod_funcs->texture_render_size;
|
||||
byte *render_data = 0;
|
||||
if (render_size) {
|
||||
render_data = Hunk_AllocName (m->nummiptex * render_size,
|
||||
render_data = Hunk_AllocName (0, m->nummiptex * render_size,
|
||||
mod->name);
|
||||
}
|
||||
for (i = 0; i < m->nummiptex; i++) {
|
||||
|
@ -397,7 +398,7 @@ Mod_LoadVisibility (model_t *mod, bsp_t *bsp)
|
|||
mod->brush.visdata = NULL;
|
||||
return;
|
||||
}
|
||||
mod->brush.visdata = Hunk_AllocName (bsp->visdatasize, mod->name);
|
||||
mod->brush.visdata = Hunk_AllocName (0, bsp->visdatasize, mod->name);
|
||||
memcpy (mod->brush.visdata, bsp->visdata, bsp->visdatasize);
|
||||
}
|
||||
|
||||
|
@ -408,7 +409,7 @@ Mod_LoadEntities (model_t *mod, bsp_t *bsp)
|
|||
mod->brush.entities = NULL;
|
||||
return;
|
||||
}
|
||||
mod->brush.entities = Hunk_AllocName (bsp->entdatasize, mod->name);
|
||||
mod->brush.entities = Hunk_AllocName (0, bsp->entdatasize, mod->name);
|
||||
memcpy (mod->brush.entities, bsp->entdata, bsp->entdatasize);
|
||||
}
|
||||
|
||||
|
@ -421,7 +422,7 @@ Mod_LoadVertexes (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->vertexes;
|
||||
count = bsp->numvertexes;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
mod->brush.vertexes = out;
|
||||
mod->brush.numvertexes = count;
|
||||
|
@ -439,7 +440,7 @@ Mod_LoadSubmodels (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->models;
|
||||
count = bsp->nummodels;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
brush->submodels = out;
|
||||
brush->numsubmodels = count;
|
||||
|
@ -474,7 +475,7 @@ Mod_LoadEdges (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->edges;
|
||||
count = bsp->numedges;
|
||||
out = Hunk_AllocName ((count + 1) * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, (count + 1) * sizeof (*out), mod->name);
|
||||
|
||||
mod->brush.edges = out;
|
||||
mod->brush.numedges = count;
|
||||
|
@ -495,7 +496,7 @@ Mod_LoadTexinfo (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->texinfo;
|
||||
count = bsp->numtexinfo;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
mod->brush.texinfo = out;
|
||||
mod->brush.numtexinfo = count;
|
||||
|
@ -597,7 +598,7 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->faces;
|
||||
count = bsp->numfaces;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
if (count > 32767) {
|
||||
Sys_MaskPrintf (SYS_warn,
|
||||
|
@ -698,7 +699,7 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->nodes;
|
||||
count = bsp->numnodes;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
if (count > 32767) {
|
||||
Sys_MaskPrintf (SYS_warn,
|
||||
|
@ -742,7 +743,7 @@ Mod_LoadNodes (model_t *mod, bsp_t *bsp)
|
|||
|
||||
size_t size = (brush->modleafs + brush->numnodes) * sizeof (mnode_t *);
|
||||
size += brush->modleafs * sizeof (int);
|
||||
brush->node_parents = Hunk_AllocName (size, mod->name);
|
||||
brush->node_parents = Hunk_AllocName (0, size, mod->name);
|
||||
brush->leaf_parents = brush->node_parents + brush->numnodes;
|
||||
brush->leaf_flags = (int *) (brush->leaf_parents + brush->modleafs);
|
||||
Mod_SetParent (brush, brush->nodes, NULL); // sets nodes and leafs
|
||||
|
@ -760,7 +761,7 @@ Mod_LoadLeafs (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->leafs;
|
||||
count = bsp->numleafs;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
brush->leafs = out;
|
||||
brush->modleafs = count;
|
||||
|
@ -813,7 +814,7 @@ Mod_LoadClipnodes (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->clipnodes;
|
||||
count = bsp->numclipnodes;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
if (count > 32767) {
|
||||
Sys_MaskPrintf (SYS_warn,
|
||||
|
@ -890,7 +891,7 @@ Mod_MakeHull0 (model_t *mod)
|
|||
|
||||
in = brush->nodes;
|
||||
count = brush->numnodes;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
hull->clipnodes = out;
|
||||
hull->firstclipnode = 0;
|
||||
|
@ -919,7 +920,7 @@ Mod_LoadMarksurfaces (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->marksurfaces;
|
||||
count = bsp->nummarksurfaces;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
if (count > 32767) {
|
||||
Sys_MaskPrintf (SYS_warn,
|
||||
|
@ -948,7 +949,7 @@ Mod_LoadSurfedges (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->surfedges;
|
||||
count = bsp->numsurfedges;
|
||||
out = Hunk_AllocName (count * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * sizeof (*out), mod->name);
|
||||
|
||||
brush->surfedges = out;
|
||||
brush->numsurfedges = count;
|
||||
|
@ -967,7 +968,7 @@ Mod_LoadPlanes (model_t *mod, bsp_t *bsp)
|
|||
|
||||
in = bsp->planes;
|
||||
count = bsp->numplanes;
|
||||
out = Hunk_AllocName (count * 2 * sizeof (*out), mod->name);
|
||||
out = Hunk_AllocName (0, count * 2 * sizeof (*out), mod->name);
|
||||
|
||||
brush->planes = out;
|
||||
brush->numplanes = count;
|
||||
|
|
|
@ -48,6 +48,6 @@ sw_Mod_LoadLighting (model_t *mod, bsp_t *bsp)
|
|||
mod->brush.lightdata = NULL;
|
||||
return;
|
||||
}
|
||||
mod->brush.lightdata = Hunk_AllocName (bsp->lightdatasize, mod->name);
|
||||
mod->brush.lightdata = Hunk_AllocName (0, bsp->lightdatasize, mod->name);
|
||||
memcpy (mod->brush.lightdata, bsp->lightdata, bsp->lightdatasize);
|
||||
}
|
||||
|
|
|
@ -318,7 +318,7 @@ Vulkan_Mod_ProcessTexture (model_t *mod, texture_t *tx, vulkan_ctx_t *ctx)
|
|||
qfv_device_t *device = ctx->device;
|
||||
|
||||
if (!tx) {
|
||||
modelctx_t *mctx = Hunk_AllocName (sizeof (modelctx_t), mod->name);
|
||||
modelctx_t *mctx = Hunk_AllocName (0, sizeof (modelctx_t), mod->name);
|
||||
mctx->ctx = ctx;
|
||||
mod->clear = vulkan_brush_clear;
|
||||
mod->data = mctx;
|
||||
|
@ -360,11 +360,11 @@ Vulkan_Mod_ProcessTexture (model_t *mod, texture_t *tx, vulkan_ctx_t *ctx)
|
|||
|
||||
const char *name = va (ctx->va_ctx, "fb_%s", tx->name);
|
||||
int size = (tx->width * tx->height * 85) / 64;
|
||||
int fullbright_mark = Hunk_LowMark ();
|
||||
byte *pixels = Hunk_AllocName (size, name);
|
||||
int fullbright_mark = Hunk_LowMark (0);
|
||||
byte *pixels = Hunk_AllocName (0, size, name);
|
||||
|
||||
if (!Mod_CalcFullbright ((byte *) (tx + 1), pixels, size)) {
|
||||
Hunk_FreeToLowMark (fullbright_mark);
|
||||
Hunk_FreeToLowMark (0, fullbright_mark);
|
||||
return;
|
||||
}
|
||||
tex->glow = tex->tex + 1;
|
||||
|
@ -428,7 +428,7 @@ Vulkan_Mod_LoadLighting (model_t *mod, bsp_t *bsp, vulkan_ctx_t *ctx)
|
|||
return;
|
||||
}
|
||||
// LordHavoc: oh well, expand the white lighting data
|
||||
brush->lightdata = Hunk_AllocName (bsp->lightdatasize * 3, mod->name);
|
||||
brush->lightdata = Hunk_AllocName (0, bsp->lightdatasize * 3, mod->name);
|
||||
in = bsp->lightdata;
|
||||
out = brush->lightdata;
|
||||
|
||||
|
|
|
@ -73,7 +73,8 @@ Mod_Init (void)
|
|||
int m, x, y;
|
||||
int mip0size = 16*16, mip1size = 8*8, mip2size = 4*4, mip3size = 2*2;
|
||||
|
||||
r_notexture_mip = Hunk_AllocName (sizeof (texture_t) + mip0size + mip1size
|
||||
r_notexture_mip = Hunk_AllocName (0,
|
||||
sizeof (texture_t) + mip0size + mip1size
|
||||
+ mip2size + mip3size, "notexture");
|
||||
|
||||
r_notexture_mip->width = r_notexture_mip->height = 16;
|
||||
|
|
|
@ -55,7 +55,8 @@ Mod_LoadSpriteFrame (model_t *mod, void *pin, mspriteframe_t **ppframe,
|
|||
height = LittleLong (pinframe->height);
|
||||
size = width * height;
|
||||
|
||||
pspriteframe = Hunk_AllocName (sizeof (mspriteframe_t) + size, mod->name);
|
||||
pspriteframe = Hunk_AllocName (0, sizeof (mspriteframe_t) + size,
|
||||
mod->name);
|
||||
|
||||
memset (pspriteframe, 0, sizeof (mspriteframe_t) + size);
|
||||
|
||||
|
@ -93,7 +94,7 @@ Mod_LoadSpriteGroup (model_t *mod, void *pin, mspriteframe_t **ppframe,
|
|||
|
||||
numframes = LittleLong (pingroup->numframes);
|
||||
|
||||
pspritegroup = Hunk_AllocName (field_offset (mspritegroup_t,
|
||||
pspritegroup = Hunk_AllocName (0, field_offset (mspritegroup_t,
|
||||
frames[numframes]),
|
||||
mod->name);
|
||||
|
||||
|
@ -103,7 +104,7 @@ Mod_LoadSpriteGroup (model_t *mod, void *pin, mspriteframe_t **ppframe,
|
|||
|
||||
pin_intervals = (dspriteinterval_t *) (pingroup + 1);
|
||||
|
||||
poutintervals = Hunk_AllocName (numframes * sizeof (float), mod->name);
|
||||
poutintervals = Hunk_AllocName (0, numframes * sizeof (float), mod->name);
|
||||
|
||||
pspritegroup->intervals = poutintervals;
|
||||
|
||||
|
@ -146,7 +147,7 @@ Mod_LoadSpriteModel (model_t *mod, void *buffer)
|
|||
|
||||
size = field_offset (msprite_t, frames[numframes]);
|
||||
|
||||
psprite = Hunk_AllocName (size, mod->name);
|
||||
psprite = Hunk_AllocName (0, size, mod->name);
|
||||
|
||||
mod->cache.data = psprite;
|
||||
|
||||
|
|
|
@ -835,7 +835,7 @@ NET_Init (void)
|
|||
SetNetTime ();
|
||||
|
||||
for (i = 0; i < net_numsockets; i++) {
|
||||
s = (qsocket_t *) Hunk_AllocName (sizeof (qsocket_t), "qsocket");
|
||||
s = (qsocket_t *) Hunk_AllocName (0, sizeof (qsocket_t), "qsocket");
|
||||
s->next = net_freeSockets;
|
||||
net_freeSockets = s;
|
||||
s->disconnected = true;
|
||||
|
|
|
@ -62,7 +62,7 @@ PF_VarString (progs_t *pr, int first)
|
|||
|
||||
for (len = 0, i = first; i < pr->pr_argc; i++)
|
||||
len += strlen (P_GSTRING (pr, i));
|
||||
dst = out = Hunk_TempAlloc (len + 1);
|
||||
dst = out = Hunk_TempAlloc (0, len + 1);
|
||||
for (i = first; i < pr->pr_argc; i++) {
|
||||
src = P_GSTRING (pr, i);
|
||||
while (*src)
|
||||
|
|
|
@ -509,7 +509,7 @@ Cmd_Exec_f (void)
|
|||
return;
|
||||
}
|
||||
|
||||
mark = Hunk_LowMark ();
|
||||
mark = Hunk_LowMark (0);
|
||||
f = (char *) QFS_LoadHunkFile (QFS_FOpenFile (Cmd_Argv (1)));
|
||||
if (!f) {
|
||||
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
||||
|
@ -520,7 +520,7 @@ Cmd_Exec_f (void)
|
|||
|| (developer && developer->int_val & SYS_dev)))
|
||||
Sys_Printf ("execing %s\n", Cmd_Argv (1));
|
||||
Cbuf_InsertText (cbuf_active, f);
|
||||
Hunk_FreeToLowMark (mark);
|
||||
Hunk_FreeToLowMark (0, mark);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -224,7 +224,7 @@ VISIBLE info_t *
|
|||
Info_ParseString (const char *s, int maxsize, int flags)
|
||||
{
|
||||
info_t *info;
|
||||
char *string = Hunk_TempAlloc (strlen (s) + 1);
|
||||
char *string = Hunk_TempAlloc (0, strlen (s) + 1);
|
||||
char *key, *value, *end;
|
||||
|
||||
info = malloc (sizeof (info_t));
|
||||
|
@ -271,7 +271,7 @@ Info_MakeString (info_t *info, int (*filter) (const char *))
|
|||
info_key_t **key_list;
|
||||
info_key_t **key;
|
||||
|
||||
d = string = Hunk_TempAlloc (info->cursize + 1);
|
||||
d = string = Hunk_TempAlloc (0, info->cursize + 1);
|
||||
key_list = (info_key_t **) Hash_GetList (info->tab);
|
||||
|
||||
for (key = key_list; *key; key++) {
|
||||
|
|
|
@ -1141,9 +1141,9 @@ QFS_LoadFile (QFile *file, int usehunk)
|
|||
//base = QFS_FileBase (path);
|
||||
|
||||
if (usehunk == 1)
|
||||
buf = Hunk_AllocName (len + 1, base);
|
||||
buf = Hunk_AllocName (0, len + 1, base);
|
||||
else if (usehunk == 2)
|
||||
buf = Hunk_TempAlloc (len + 1);
|
||||
buf = Hunk_TempAlloc (0, len + 1);
|
||||
else if (usehunk == 0)
|
||||
buf = calloc (1, len + 1);
|
||||
else if (usehunk == 3)
|
||||
|
|
|
@ -45,7 +45,7 @@ SZ_Alloc (sizebuf_t *buf, unsigned maxsize)
|
|||
{
|
||||
if (maxsize < 256)
|
||||
maxsize = 256;
|
||||
buf->data = Hunk_AllocName (maxsize, "sizebuf");
|
||||
buf->data = Hunk_AllocName (0, maxsize, "sizebuf");
|
||||
buf->maxsize = maxsize;
|
||||
buf->cursize = 0;
|
||||
}
|
||||
|
|
366
libs/util/zone.c
366
libs/util/zone.c
|
@ -48,9 +48,9 @@
|
|||
|
||||
#include "compat.h"
|
||||
|
||||
static void Cache_FreeLow (int new_low_hunk);
|
||||
static void Cache_Profile (void);
|
||||
static qboolean Cache_FreeLRU (void);
|
||||
static void Cache_FreeLow (memhunk_t *hunk, int new_low_hunk);
|
||||
static void Cache_Profile_r (memhunk_t *hunk);
|
||||
static qboolean Cache_FreeLRU (memhunk_t *hunk);
|
||||
|
||||
#define ZONEID 0x1d4a11
|
||||
#define HUNK_SENTINAL 0x1df001ed
|
||||
|
@ -409,22 +409,35 @@ Z_CheckPointer (const memzone_t *zone, const void *ptr, size_t size)
|
|||
|
||||
//============================================================================
|
||||
|
||||
typedef struct cache_system_s cache_system_t;
|
||||
struct cache_system_s {
|
||||
cache_system_t *prev, *next;
|
||||
cache_system_t *lru_prev, *lru_next; // for LRU flushing
|
||||
struct memhunk_s *hunk;
|
||||
char name[16];
|
||||
size_t size; // including this header
|
||||
int readlock;
|
||||
cache_user_t *user;
|
||||
} __attribute__((aligned (64)));//FIXME base 64-bit size is 80, so 128...
|
||||
|
||||
typedef struct {
|
||||
int sentinal1;
|
||||
int sentinal2;
|
||||
size_t size; // including sizeof(hunk_t), -1 = not allocated
|
||||
size_t size; // including sizeof(hunkblk_t), -1 = not allocated
|
||||
char name[8];
|
||||
// pad out to 64 bytes
|
||||
char fill[64 - 2 * sizeof (int) - sizeof (size_t) - 8];
|
||||
} hunk_t;
|
||||
} __attribute__((aligned (64))) hunkblk_t;
|
||||
|
||||
byte *hunk_base;
|
||||
size_t hunk_size;
|
||||
size_t hunk_low_used;
|
||||
size_t hunk_high_used;
|
||||
size_t hunk_tempmark;
|
||||
struct memhunk_s {
|
||||
byte *base;
|
||||
size_t size;
|
||||
size_t low_used;
|
||||
size_t high_used;
|
||||
size_t tempmark;
|
||||
qboolean tempactive;
|
||||
cache_system_t cache_head;
|
||||
} __attribute__((aligned (64)));
|
||||
|
||||
qboolean hunk_tempactive;
|
||||
static memhunk_t *global_hunk;
|
||||
|
||||
/*
|
||||
Hunk_Check
|
||||
|
@ -432,17 +445,19 @@ qboolean hunk_tempactive;
|
|||
Run consistancy and sentinal trahing checks
|
||||
*/
|
||||
VISIBLE void
|
||||
Hunk_Check (void)
|
||||
Hunk_Check (memhunk_t *hunk)
|
||||
{
|
||||
hunk_t *h;
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
hunkblk_t *h;
|
||||
byte *hunk_end = hunk->base + hunk->low_used;
|
||||
|
||||
for (h = (hunk_t *) hunk_base; (byte *) h < hunk_base + hunk_low_used; ) {
|
||||
for (h = (hunkblk_t *) hunk->base; (byte *) h < hunk_end; ) {
|
||||
if (h->sentinal1 != HUNK_SENTINAL || h->sentinal2 != HUNK_SENTINAL)
|
||||
Sys_Error ("Hunk_Check: trashed sentinal");
|
||||
if (h->size < sizeof (hunk_t)
|
||||
|| h->size + (byte *) h > hunk_base + hunk_size)
|
||||
if (h->size < sizeof (hunkblk_t)
|
||||
|| h->size + (byte *) h > hunk->base + hunk->size)
|
||||
Sys_Error ("Hunk_Check: bad size");
|
||||
h = (hunk_t *) ((byte *) h + h->size);
|
||||
h = (hunkblk_t *) ((byte *) h + h->size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -455,21 +470,22 @@ Hunk_Check (void)
|
|||
*/
|
||||
|
||||
VISIBLE void
|
||||
Hunk_Print (qboolean all)
|
||||
Hunk_Print (memhunk_t *hunk, qboolean all)
|
||||
{
|
||||
hunk_t *h, *next, *endlow, *starthigh, *endhigh;
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
hunkblk_t *h, *next, *endlow, *starthigh, *endhigh;
|
||||
int count, sum, totalblocks;
|
||||
|
||||
count = 0;
|
||||
sum = 0;
|
||||
totalblocks = 0;
|
||||
|
||||
h = (hunk_t *) hunk_base;
|
||||
endlow = (hunk_t *) (hunk_base + hunk_low_used);
|
||||
starthigh = (hunk_t *) (hunk_base + hunk_size - hunk_high_used);
|
||||
endhigh = (hunk_t *) (hunk_base + hunk_size);
|
||||
h = (hunkblk_t *) hunk->base;
|
||||
endlow = (hunkblk_t *) (hunk->base + hunk->low_used);
|
||||
starthigh = (hunkblk_t *) (hunk->base + hunk->size - hunk->high_used);
|
||||
endhigh = (hunkblk_t *) (hunk->base + hunk->size);
|
||||
|
||||
Sys_Printf (" :%8zd total hunk size\n", hunk_size);
|
||||
Sys_Printf (" :%8zd total hunk size\n", hunk->size);
|
||||
Sys_Printf ("-------------------------\n");
|
||||
|
||||
while (1) {
|
||||
|
@ -477,7 +493,7 @@ Hunk_Print (qboolean all)
|
|||
if (h == endlow) {
|
||||
Sys_Printf ("-------------------------\n");
|
||||
Sys_Printf (" :%8zd REMAINING\n",
|
||||
hunk_size - hunk_low_used - hunk_high_used);
|
||||
hunk->size - hunk->low_used - hunk->high_used);
|
||||
Sys_Printf ("-------------------------\n");
|
||||
h = starthigh;
|
||||
}
|
||||
|
@ -488,11 +504,11 @@ Hunk_Print (qboolean all)
|
|||
// run consistancy checks
|
||||
if (h->sentinal1 != HUNK_SENTINAL || h->sentinal2 != HUNK_SENTINAL)
|
||||
Sys_Error ("Hunk_Check: trahsed sentinal");
|
||||
if (h->size < (int) sizeof (hunk_t)
|
||||
|| h->size + (byte *) h > hunk_base + hunk_size)
|
||||
if (h->size < (int) sizeof (hunkblk_t)
|
||||
|| h->size + (byte *) h > hunk->base + hunk->size)
|
||||
Sys_Error ("Hunk_Check: bad size");
|
||||
|
||||
next = (hunk_t *) ((byte *) h + h->size);
|
||||
next = (hunkblk_t *) ((byte *) h + h->size);
|
||||
count++;
|
||||
totalblocks++;
|
||||
sum += h->size;
|
||||
|
@ -518,59 +534,63 @@ Hunk_Print (qboolean all)
|
|||
}
|
||||
|
||||
static void
|
||||
Hunk_FreeToHighMark (size_t mark)
|
||||
Hunk_FreeToHighMark (memhunk_t *hunk, size_t mark)
|
||||
{
|
||||
if (hunk_tempactive) {
|
||||
hunk_tempactive = false;
|
||||
Hunk_FreeToHighMark (hunk_tempmark);
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
if (hunk->tempactive) {
|
||||
hunk->tempactive = false;
|
||||
Hunk_FreeToHighMark (hunk, hunk->tempmark);
|
||||
}
|
||||
if (mark > hunk_high_used)
|
||||
if (mark > hunk->high_used)
|
||||
Sys_Error ("Hunk_FreeToHighMark: bad mark %zd", mark);
|
||||
memset (hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
|
||||
hunk_high_used = mark;
|
||||
memset (hunk->base + hunk->size - hunk->high_used, 0,
|
||||
hunk->high_used - mark);
|
||||
hunk->high_used = mark;
|
||||
}
|
||||
|
||||
static int
|
||||
Hunk_HighMark (void)
|
||||
Hunk_HighMark (memhunk_t *hunk)
|
||||
{
|
||||
if (hunk_tempactive) {
|
||||
hunk_tempactive = false;
|
||||
Hunk_FreeToHighMark (hunk_tempmark);
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
if (hunk->tempactive) {
|
||||
hunk->tempactive = false;
|
||||
Hunk_FreeToHighMark (hunk, hunk->tempmark);
|
||||
}
|
||||
|
||||
return hunk_high_used;
|
||||
return hunk->high_used;
|
||||
}
|
||||
|
||||
VISIBLE void *
|
||||
Hunk_AllocName (size_t size, const char *name)
|
||||
Hunk_AllocName (memhunk_t *hunk, size_t size, const char *name)
|
||||
{
|
||||
hunk_t *h;
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
hunkblk_t *h;
|
||||
|
||||
#ifdef PARANOID
|
||||
Hunk_Check ();
|
||||
#endif
|
||||
|
||||
size = sizeof (hunk_t) + ((size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1));
|
||||
size = sizeof (hunkblk_t) + ((size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1));
|
||||
|
||||
if (hunk_size - hunk_low_used - hunk_high_used < size) {
|
||||
Hunk_HighMark();
|
||||
Cache_FreeLRU ();
|
||||
if (hunk->size - hunk->low_used - hunk->high_used < size) {
|
||||
Hunk_HighMark (hunk);
|
||||
Cache_FreeLRU (hunk);
|
||||
}
|
||||
if (hunk_size - hunk_low_used - hunk_high_used < size) {
|
||||
int mem = hunk_size / (1024 * 1024);
|
||||
if (hunk->size - hunk->low_used - hunk->high_used < size) {
|
||||
int mem = hunk->size / (1024 * 1024);
|
||||
mem += 8;
|
||||
mem &= ~7;
|
||||
Cache_Profile ();
|
||||
Cache_Profile_r (hunk);
|
||||
Sys_Error
|
||||
("Not enough RAM allocated. Try starting using \"-mem %d\" on "
|
||||
"the %s command line. (%zd - %zd - %zd < %zd)", mem,
|
||||
PACKAGE_NAME, hunk_size, hunk_low_used, hunk_high_used, size);
|
||||
PACKAGE_NAME, hunk->size, hunk->low_used, hunk->high_used, size);
|
||||
}
|
||||
|
||||
h = (hunk_t *) (hunk_base + hunk_low_used);
|
||||
hunk_low_used += size;
|
||||
h = (hunkblk_t *) (hunk->base + hunk->low_used);
|
||||
hunk->low_used += size;
|
||||
|
||||
Cache_FreeLow (hunk_low_used);
|
||||
Cache_FreeLow (hunk, hunk->low_used);
|
||||
|
||||
memset (h, 0, size);
|
||||
|
||||
|
@ -584,49 +604,52 @@ Hunk_AllocName (size_t size, const char *name)
|
|||
}
|
||||
|
||||
VISIBLE void *
|
||||
Hunk_Alloc (size_t size)
|
||||
Hunk_Alloc (memhunk_t *hunk, size_t size)
|
||||
{
|
||||
return Hunk_AllocName (size, "unknown");
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
return Hunk_AllocName (hunk, size, "unknown");
|
||||
}
|
||||
|
||||
VISIBLE size_t
|
||||
Hunk_LowMark (void)
|
||||
Hunk_LowMark (memhunk_t *hunk)
|
||||
{
|
||||
return hunk_low_used;
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
return hunk->low_used;
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
Hunk_FreeToLowMark (size_t mark)
|
||||
Hunk_FreeToLowMark (memhunk_t *hunk, size_t mark)
|
||||
{
|
||||
if (mark > hunk_low_used)
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
if (mark > hunk->low_used)
|
||||
Sys_Error ("Hunk_FreeToLowMark: bad mark %zd", mark);
|
||||
memset (hunk_base + mark, 0, hunk_low_used - mark);
|
||||
hunk_low_used = mark;
|
||||
memset (hunk->base + mark, 0, hunk->low_used - mark);
|
||||
hunk->low_used = mark;
|
||||
}
|
||||
|
||||
static void *
|
||||
Hunk_HighAlloc (size_t size)
|
||||
Hunk_HighAlloc (memhunk_t *hunk, size_t size)
|
||||
{
|
||||
hunk_t *h;
|
||||
hunkblk_t *h;
|
||||
|
||||
if (hunk_tempactive) {
|
||||
Hunk_FreeToHighMark (hunk_tempmark);
|
||||
hunk_tempactive = false;
|
||||
if (hunk->tempactive) {
|
||||
Hunk_FreeToHighMark (hunk, hunk->tempmark);
|
||||
hunk->tempactive = false;
|
||||
}
|
||||
#ifdef PARANOID
|
||||
Hunk_Check ();
|
||||
Hunk_Check (hunk);
|
||||
#endif
|
||||
|
||||
size = sizeof (hunk_t) + ((size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1));
|
||||
size = sizeof (hunkblk_t) + ((size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1));
|
||||
|
||||
if (hunk_size - hunk_low_used - hunk_high_used < size) {
|
||||
if (hunk->size - hunk->low_used - hunk->high_used < size) {
|
||||
Sys_Printf ("Hunk_HighAlloc: failed on %zd bytes\n", size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hunk_high_used += size;
|
||||
hunk->high_used += size;
|
||||
|
||||
h = (void *) (hunk_base + hunk_size - hunk_high_used);
|
||||
h = (void *) (hunk->base + hunk->size - hunk->high_used);
|
||||
h->sentinal1 = HUNK_SENTINAL;
|
||||
h->sentinal2 = HUNK_SENTINAL;
|
||||
h->size = size;
|
||||
|
@ -640,44 +663,37 @@ Hunk_HighAlloc (size_t size)
|
|||
Return space from the top of the hunk
|
||||
*/
|
||||
VISIBLE void *
|
||||
Hunk_TempAlloc (size_t size)
|
||||
Hunk_TempAlloc (memhunk_t *hunk, size_t size)
|
||||
{
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
void *buf;
|
||||
|
||||
size = (size + HUNK_ALIGN - 1) & ~(HUNK_ALIGN - 1);
|
||||
|
||||
if (hunk_tempactive) {
|
||||
if (hunk_high_used - hunk_tempmark >= size + (int) sizeof (hunk_t)) {
|
||||
return (hunk_t *) (hunk_base + hunk_size - hunk_high_used) + 1;
|
||||
if (hunk->tempactive) {
|
||||
size_t temp_free = hunk->high_used - hunk->tempmark;
|
||||
if (temp_free >= size + (int) sizeof (hunkblk_t)) {
|
||||
byte *temp_block = hunk->base + hunk->size - hunk->high_used;
|
||||
return (hunkblk_t *) temp_block + 1;
|
||||
}
|
||||
Hunk_FreeToHighMark (hunk_tempmark);
|
||||
hunk_tempactive = false;
|
||||
Hunk_FreeToHighMark (hunk, hunk->tempmark);
|
||||
hunk->tempactive = false;
|
||||
}
|
||||
|
||||
hunk_tempmark = Hunk_HighMark ();
|
||||
hunk->tempmark = Hunk_HighMark (hunk);
|
||||
|
||||
buf = Hunk_HighAlloc (size);
|
||||
buf = Hunk_HighAlloc (hunk, size);
|
||||
|
||||
hunk_tempactive = true;
|
||||
hunk->tempactive = true;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* CACHE MEMORY */
|
||||
|
||||
typedef struct cache_system_s cache_system_t;
|
||||
struct cache_system_s {
|
||||
cache_system_t *prev, *next;
|
||||
cache_system_t *lru_prev, *lru_next; // for LRU flushing
|
||||
char name[16];
|
||||
size_t size; // including this header
|
||||
int readlock;
|
||||
cache_user_t *user;
|
||||
};
|
||||
|
||||
static cache_system_t cache_head;
|
||||
|
||||
static cache_system_t *Cache_TryAlloc (size_t size, qboolean nobottom);
|
||||
static cache_system_t *Cache_TryAlloc (memhunk_t *hunk, size_t size,
|
||||
qboolean nobottom);
|
||||
#if 0
|
||||
static void
|
||||
check_cache (void)
|
||||
|
@ -702,10 +718,11 @@ check_cache (void)
|
|||
static void
|
||||
Cache_Move (cache_system_t *c)
|
||||
{
|
||||
memhunk_t *hunk = c->hunk;
|
||||
cache_system_t *new;
|
||||
|
||||
// we are clearing up space at the bottom, so allocate it late
|
||||
new = Cache_TryAlloc (c->size, true);
|
||||
new = Cache_TryAlloc (hunk, c->size, true);
|
||||
if (new) {
|
||||
Sys_MaskPrintf (SYS_dev, "cache_move ok\n");
|
||||
|
||||
|
@ -727,15 +744,15 @@ Cache_Move (cache_system_t * c)
|
|||
Throw things out until the hunk can be expanded to the given point
|
||||
*/
|
||||
static void
|
||||
Cache_FreeLow (int new_low_hunk)
|
||||
Cache_FreeLow (memhunk_t *hunk, int new_low_hunk)
|
||||
{
|
||||
cache_system_t *c;
|
||||
|
||||
while (1) {
|
||||
c = cache_head.prev;
|
||||
if (c == &cache_head)
|
||||
c = hunk->cache_head.prev;
|
||||
if (c == &hunk->cache_head)
|
||||
return; // nothing in cache at all
|
||||
if ((byte *) c >= hunk_base + new_low_hunk)
|
||||
if ((byte *) c >= hunk->base + new_low_hunk)
|
||||
return; // there is space to grow the hunk
|
||||
Sys_Error ("FIXME: Cache_FreeLow: not enough memory");
|
||||
Cache_Move (c); // reclaim the space
|
||||
|
@ -762,22 +779,22 @@ Cache_MakeLRU (cache_system_t * cs)
|
|||
Sys_Error ("Cache_MakeLRU: active link: %.16s %p %p",
|
||||
cs->name, cs->lru_next, cs->lru_prev);
|
||||
|
||||
cache_head.lru_next->lru_prev = cs;
|
||||
cs->lru_next = cache_head.lru_next;
|
||||
cs->lru_prev = &cache_head;
|
||||
cache_head.lru_next = cs;
|
||||
cs->hunk->cache_head.lru_next->lru_prev = cs;
|
||||
cs->lru_next = cs->hunk->cache_head.lru_next;
|
||||
cs->lru_prev = &cs->hunk->cache_head;
|
||||
cs->hunk->cache_head.lru_next = cs;
|
||||
}
|
||||
|
||||
static qboolean
|
||||
Cache_FreeLRU (void)
|
||||
Cache_FreeLRU (memhunk_t *hunk)
|
||||
{
|
||||
cache_system_t *cs;
|
||||
|
||||
//check_cache ();
|
||||
for (cs = cache_head.lru_prev;
|
||||
cs != &cache_head && cs->readlock; cs = cs->lru_prev)
|
||||
for (cs = hunk->cache_head.lru_prev;
|
||||
cs != &hunk->cache_head && cs->readlock; cs = cs->lru_prev)
|
||||
;
|
||||
if (cs == &cache_head)
|
||||
if (cs == &hunk->cache_head)
|
||||
return 0;
|
||||
Cache_Free (cs->user);
|
||||
return 1;
|
||||
|
@ -800,27 +817,28 @@ link_cache_system (cache_system_t *new, cache_system_t *cs)
|
|||
Size should already include the header and padding
|
||||
*/
|
||||
static cache_system_t *
|
||||
Cache_TryAlloc (size_t size, qboolean nobottom)
|
||||
Cache_TryAlloc (memhunk_t *hunk, size_t size, qboolean nobottom)
|
||||
{
|
||||
cache_system_t *cs, *new;
|
||||
|
||||
//check_cache ();
|
||||
// is the cache completely empty?
|
||||
if (!nobottom && cache_head.prev == &cache_head) {
|
||||
new = (cache_system_t *) Hunk_HighAlloc (size);
|
||||
if (!nobottom && hunk->cache_head.prev == &hunk->cache_head) {
|
||||
new = (cache_system_t *) Hunk_HighAlloc (hunk, size);
|
||||
if (!new)
|
||||
return 0;
|
||||
memset (new, 0, size);
|
||||
new->size = size;
|
||||
cache_head.prev = cache_head.next = new;
|
||||
new->prev = new->next = &cache_head;
|
||||
new->hunk = hunk;
|
||||
hunk->cache_head.prev = hunk->cache_head.next = new;
|
||||
new->prev = new->next = &hunk->cache_head;
|
||||
Cache_MakeLRU (new);
|
||||
//check_cache ();
|
||||
return new;
|
||||
}
|
||||
|
||||
// search for space in existing cache
|
||||
for (cs = cache_head.next; cs != &cache_head; cs = cs->next) {
|
||||
for (cs = hunk->cache_head.next; cs != &hunk->cache_head; cs = cs->next) {
|
||||
if (cs->user)
|
||||
continue; // block isn't free
|
||||
if (cs->size >= size) {
|
||||
|
@ -832,6 +850,7 @@ Cache_TryAlloc (size_t size, qboolean nobottom)
|
|||
new = (cache_system_t *) ((char *) cs + cs->size - size);
|
||||
memset (new, 0, size);
|
||||
new->size = size;
|
||||
new->hunk = hunk;
|
||||
cs->size -= size;
|
||||
link_cache_system (new, cs);
|
||||
//check_cache ();
|
||||
|
@ -845,11 +864,12 @@ Cache_TryAlloc (size_t size, qboolean nobottom)
|
|||
return 0;
|
||||
|
||||
// didn't find a free block, so make a new one.
|
||||
new = Hunk_HighAlloc (size);
|
||||
new = Hunk_HighAlloc (hunk, size);
|
||||
if (new) {
|
||||
memset (new, 0, size);
|
||||
new->size = size;
|
||||
link_cache_system (new, &cache_head);
|
||||
new->hunk = hunk;
|
||||
link_cache_system (new, &hunk->cache_head);
|
||||
Cache_MakeLRU (new);
|
||||
//check_cache ();
|
||||
return new;
|
||||
|
@ -859,15 +879,15 @@ Cache_TryAlloc (size_t size, qboolean nobottom)
|
|||
}
|
||||
|
||||
static void
|
||||
Cache_Profile (void)
|
||||
Cache_Profile_r (memhunk_t *hunk)
|
||||
{
|
||||
cache_system_t *cs;
|
||||
unsigned int i;
|
||||
unsigned int items[31] = {0}, sizes[31] = {0};
|
||||
int count = 0, total = 0;
|
||||
|
||||
cs = cache_head.next;
|
||||
while (cs != &cache_head) {
|
||||
cs = hunk->cache_head.next;
|
||||
while (cs != &hunk->cache_head) {
|
||||
for (i = 0; (cs->size >> (i + 1)) && i < 30; i++)
|
||||
;
|
||||
items[i]++;
|
||||
|
@ -893,23 +913,39 @@ Cache_Profile (void)
|
|||
}
|
||||
|
||||
static void
|
||||
Cache_Print (void)
|
||||
Cache_Profile (void)
|
||||
{
|
||||
Cache_Profile_r (global_hunk);
|
||||
}
|
||||
|
||||
static void
|
||||
Cache_Print_r (memhunk_t *hunk)
|
||||
{
|
||||
cache_system_t *cd;
|
||||
|
||||
for (cd = cache_head.next; cd != &cache_head; cd = cd->next) {
|
||||
for (cd = hunk->cache_head.next; cd != &hunk->cache_head; cd = cd->next) {
|
||||
Sys_Printf ("%8d : %.16s\n", (int) cd->size, cd->name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Cache_Print (void)
|
||||
{
|
||||
Cache_Print_r (global_hunk);
|
||||
}
|
||||
|
||||
static void
|
||||
init_cache (memhunk_t *hunk)
|
||||
{
|
||||
hunk->cache_head.next = hunk->cache_head.prev = &hunk->cache_head;
|
||||
hunk->cache_head.lru_next = hunk->cache_head.lru_prev = &hunk->cache_head;
|
||||
hunk->cache_head.user = (cache_user_t *) 1; // make it look allocated
|
||||
hunk->cache_head.readlock = 1; // don't try to free or move it
|
||||
}
|
||||
|
||||
static void
|
||||
Cache_Init (void)
|
||||
{
|
||||
cache_head.next = cache_head.prev = &cache_head;
|
||||
cache_head.lru_next = cache_head.lru_prev = &cache_head;
|
||||
cache_head.user = (cache_user_t *) 1; // make it look allocated
|
||||
cache_head.readlock = 1; // don't try to free or move it
|
||||
|
||||
Cmd_AddCommand ("cache_flush", Cache_Flush, "Clears the current game "
|
||||
"cache");
|
||||
Cmd_AddCommand ("cache_profile", Cache_Profile, "Prints a profile of "
|
||||
|
@ -923,20 +959,28 @@ Cache_Init (void)
|
|||
|
||||
Throw everything out, so new data will be demand cached
|
||||
*/
|
||||
void
|
||||
Cache_Flush (void)
|
||||
static void
|
||||
Cache_Flush_r (memhunk_t *hunk)
|
||||
{
|
||||
// cache_head.prev is guaranteed to not be free because it's the bottom
|
||||
// one and Cache_Free actually properly releases it
|
||||
while (cache_head.prev != &cache_head) {
|
||||
if (!cache_head.prev->user->data)
|
||||
while (hunk->cache_head.prev != &hunk->cache_head) {
|
||||
if (!hunk->cache_head.prev->user->data)
|
||||
Sys_Error ("Cache_Flush: user/system out of sync for "
|
||||
"'%.16s' with %d size",
|
||||
cache_head.prev->name, (int) cache_head.prev->size);
|
||||
Cache_Free (cache_head.prev->user); // reclaim the space
|
||||
hunk->cache_head.prev->name,
|
||||
(int) hunk->cache_head.prev->size);
|
||||
Cache_Free (hunk->cache_head.prev->user); // reclaim the space
|
||||
}
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
Cache_Flush (void)
|
||||
{
|
||||
// cache_head.prev is guaranteed to not be free because it's the bottom
|
||||
Cache_Flush_r (global_hunk);
|
||||
}
|
||||
|
||||
VISIBLE void *
|
||||
Cache_Check (cache_user_t *c)
|
||||
{
|
||||
|
@ -968,6 +1012,7 @@ Cache_Free (cache_user_t *c)
|
|||
Sys_Error ("Cache_Free: not allocated");
|
||||
|
||||
cs = ((cache_system_t *) c->data) - 1;
|
||||
memhunk_t *hunk = cs->hunk;
|
||||
|
||||
if (cs->readlock)
|
||||
Sys_Error ("Cache_Free: attempt to free locked block");
|
||||
|
@ -989,35 +1034,36 @@ Cache_Free (cache_user_t *c)
|
|||
cs->prev->prev->next = cs;
|
||||
cs->prev = cs->prev->prev;
|
||||
}
|
||||
if (cs->next == &cache_head) {
|
||||
if (cs->next == &hunk->cache_head) {
|
||||
cs->next->prev = cs->prev;
|
||||
cs->prev->next = cs->next;
|
||||
if (cs->prev != &cache_head)
|
||||
Hunk_FreeToHighMark (hunk_size - ((byte*)cs->prev - hunk_base));
|
||||
if (cs->prev != &hunk->cache_head)
|
||||
Hunk_FreeToHighMark (hunk,
|
||||
hunk->size - ((byte*)cs->prev - hunk->base));
|
||||
else
|
||||
Hunk_FreeToHighMark (0);
|
||||
Hunk_FreeToHighMark (hunk, 0);
|
||||
}
|
||||
//check_cache ();
|
||||
|
||||
c->data = NULL;
|
||||
}
|
||||
|
||||
VISIBLE void *
|
||||
Cache_Alloc (cache_user_t *c, size_t size, const char *name)
|
||||
static void *
|
||||
Cache_Alloc_r (memhunk_t *hunk, cache_user_t *c, size_t size, const char *name)
|
||||
{
|
||||
cache_system_t *cs;
|
||||
|
||||
if (c->data)
|
||||
Sys_Error ("Cache_Alloc: already allocated");
|
||||
Sys_Error ("Cache_Alloc_r: already allocated");
|
||||
|
||||
if (size <= 0)
|
||||
Sys_Error ("Cache_Alloc: size %zd", size);
|
||||
Sys_Error ("Cache_Alloc_r: size %zd", size);
|
||||
|
||||
size = (size + sizeof (cache_system_t) + HUNK_ALIGN - 1) & ~(HUNK_ALIGN-1);
|
||||
|
||||
// find memory for it
|
||||
while (1) {
|
||||
cs = Cache_TryAlloc (size, false);
|
||||
cs = Cache_TryAlloc (hunk, size, false);
|
||||
if (cs) {
|
||||
strncpy (cs->name, name, sizeof (cs->name) - 1);
|
||||
c->data = (void *) (cs + 1);
|
||||
|
@ -1025,19 +1071,32 @@ Cache_Alloc (cache_user_t *c, size_t size, const char *name)
|
|||
break;
|
||||
}
|
||||
// free the least recently used cachedat
|
||||
if (!Cache_FreeLRU())
|
||||
if (!Cache_FreeLRU (hunk))
|
||||
Sys_Error ("Cache_Alloc: out of memory");
|
||||
}
|
||||
|
||||
return Cache_Check (c);
|
||||
}
|
||||
|
||||
VISIBLE void *
|
||||
Cache_Alloc (cache_user_t *c, size_t size, const char *name)
|
||||
{
|
||||
return Cache_Alloc_r (global_hunk, c, size, name);
|
||||
}
|
||||
|
||||
static void
|
||||
Cache_Report_r (memhunk_t *hunk)
|
||||
{
|
||||
if (!hunk) { hunk = global_hunk; } //FIXME clean up callers
|
||||
Sys_MaskPrintf (SYS_dev, "%4.1f megabyte data cache\n",
|
||||
(hunk->size - hunk->high_used -
|
||||
hunk->low_used) / (float) (1024 * 1024));
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
Cache_Report (void)
|
||||
{
|
||||
Sys_MaskPrintf (SYS_dev, "%4.1f megabyte data cache\n",
|
||||
(hunk_size - hunk_high_used -
|
||||
hunk_low_used) / (float) (1024 * 1024));
|
||||
Cache_Report_r (global_hunk);
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
|
@ -1116,13 +1175,22 @@ Cache_ReadLock (cache_user_t *c)
|
|||
|
||||
//============================================================================
|
||||
|
||||
VISIBLE memhunk_t *
|
||||
Hunk_Init (void *buf, size_t size)
|
||||
{
|
||||
memhunk_t *hunk = buf;
|
||||
hunk->base = (byte *) (hunk + 1);
|
||||
hunk->size = size - sizeof (memhunk_t);
|
||||
hunk->low_used = 0;
|
||||
hunk->high_used = 0;
|
||||
|
||||
init_cache (hunk);
|
||||
return hunk;
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
Memory_Init (void *buf, size_t size)
|
||||
{
|
||||
hunk_base = buf;
|
||||
hunk_size = size;
|
||||
hunk_low_used = 0;
|
||||
hunk_high_used = 0;
|
||||
|
||||
global_hunk = Hunk_Init (buf, size);
|
||||
Cache_Init ();
|
||||
}
|
||||
|
|
|
@ -459,7 +459,7 @@ do_subimage_2 (int i)
|
|||
|
||||
width = rect->w * lightmap_bytes;
|
||||
stride = BLOCK_WIDTH * lightmap_bytes;
|
||||
b = block = Hunk_TempAlloc (rect->h * width);
|
||||
b = block = Hunk_TempAlloc (0, rect->h * width);
|
||||
lm = lightmaps[i] + (rect->t * BLOCK_WIDTH + rect->l) * lightmap_bytes;
|
||||
for (i = rect->h; i > 0; i--) {
|
||||
memcpy (b, lm, width);
|
||||
|
|
|
@ -292,7 +292,7 @@ GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t *e)
|
|||
verts = (trivertx16_t *) ((byte *) paliashdr + paliashdr->posedata);
|
||||
|
||||
count = paliashdr->poseverts;
|
||||
vo = Hunk_TempAlloc (sizeof (*vo) + count * sizeof (blended_vert_t));
|
||||
vo = Hunk_TempAlloc (0, sizeof (*vo) + count * sizeof (blended_vert_t));
|
||||
vo->order = (int *) ((byte *) paliashdr + paliashdr->commands);
|
||||
vo->verts = (blended_vert_t *) &vo[1];
|
||||
if (paliashdr->tex_coord) {
|
||||
|
@ -358,7 +358,7 @@ GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t *e)
|
|||
verts = (trivertx_t *) ((byte *) paliashdr + paliashdr->posedata);
|
||||
|
||||
count = paliashdr->poseverts;
|
||||
vo = Hunk_TempAlloc (sizeof (*vo) + count * sizeof (blended_vert_t));
|
||||
vo = Hunk_TempAlloc (0, sizeof (*vo) + count * sizeof (blended_vert_t));
|
||||
vo->order = (int *) ((byte *) paliashdr + paliashdr->commands);
|
||||
vo->verts = (blended_vert_t *) &vo[1];
|
||||
if (paliashdr->tex_coord) {
|
||||
|
|
|
@ -840,7 +840,7 @@ GL_BuildSurfaceDisplayList (msurface_t *surf)
|
|||
lnumverts = surf->numedges;
|
||||
|
||||
// draw texture
|
||||
poly = Hunk_Alloc (sizeof (glpoly_t) + (lnumverts - 4) *
|
||||
poly = Hunk_Alloc (0, sizeof (glpoly_t) + (lnumverts - 4) *
|
||||
VERTEXSIZE * sizeof (float));
|
||||
poly->next = surf->polys;
|
||||
poly->flags = surf->flags;
|
||||
|
|
|
@ -91,7 +91,7 @@ gl_SCR_ScreenShot (unsigned width, unsigned height)
|
|||
int count, dex, dey, dx, dy, nx, r, g, b, x, y, w, h;
|
||||
tex_t *tex;
|
||||
|
||||
snap = Hunk_TempAlloc (vid.width * vid.height * 3);
|
||||
snap = Hunk_TempAlloc (0, vid.width * vid.height * 3);
|
||||
|
||||
qfglReadPixels (0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE,
|
||||
snap);
|
||||
|
|
|
@ -76,7 +76,7 @@ R_IQMBlendFrames (const iqm_t *iqm, int frame1, int frame2, float blend,
|
|||
iqmframe_t *frame;
|
||||
int i;
|
||||
|
||||
frame = Hunk_TempAlloc (iqm->num_joints * sizeof (iqmframe_t) + extra);
|
||||
frame = Hunk_TempAlloc (0, iqm->num_joints * sizeof (iqmframe_t) + extra);
|
||||
if (iqm->num_frames) {
|
||||
#if 0
|
||||
for (i = 0; i < iqm->num_joints; i++) {
|
||||
|
|
|
@ -636,7 +636,7 @@ R_AliasDrawModel (alight_t *plighting)
|
|||
size = (CACHE_SIZE - 1)
|
||||
+ sizeof (finalvert_t) * (pmdl->numverts + 1)
|
||||
+ sizeof (auxvert_t) * pmdl->numverts;
|
||||
finalverts = (finalvert_t *) Hunk_TempAlloc (size);
|
||||
finalverts = (finalvert_t *) Hunk_TempAlloc (0, size);
|
||||
if (!finalverts)
|
||||
Sys_Error ("R_AliasDrawModel: out of memory");
|
||||
|
||||
|
|
|
@ -190,7 +190,8 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
|
|||
r_cnumsurfs = MINSURFACES;
|
||||
|
||||
if (r_cnumsurfs > NUMSTACKSURFACES) {
|
||||
surfaces = Hunk_AllocName (r_cnumsurfs * sizeof (surf_t), "surfaces");
|
||||
surfaces = Hunk_AllocName (0, r_cnumsurfs * sizeof (surf_t),
|
||||
"surfaces");
|
||||
|
||||
surface_p = surfaces;
|
||||
surf_max = &surfaces[r_cnumsurfs];
|
||||
|
@ -214,7 +215,7 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
|
|||
if (r_numallocatededges <= NUMSTACKEDGES) {
|
||||
auxedges = NULL;
|
||||
} else {
|
||||
auxedges = Hunk_AllocName (r_numallocatededges * sizeof (edge_t),
|
||||
auxedges = Hunk_AllocName (0, r_numallocatededges * sizeof (edge_t),
|
||||
"edges");
|
||||
}
|
||||
|
||||
|
@ -842,7 +843,7 @@ R_RenderView (void)
|
|||
if (delta < -10000 || delta > 10000)
|
||||
Sys_Error ("R_RenderView: called without enough stack");
|
||||
|
||||
if (Hunk_LowMark () & 3)
|
||||
if (Hunk_LowMark (0) & 3)
|
||||
Sys_Error ("Hunk is missaligned");
|
||||
|
||||
if ((intptr_t) (&dummy) & 3)
|
||||
|
|
|
@ -637,7 +637,7 @@ sw32_R_AliasDrawModel (alight_t *plighting)
|
|||
size = (CACHE_SIZE - 1)
|
||||
+ sizeof (finalvert_t) * (pmdl->numverts + 1)
|
||||
+ sizeof (auxvert_t) * pmdl->numverts;
|
||||
finalverts = (finalvert_t *) Hunk_TempAlloc (size);
|
||||
finalverts = (finalvert_t *) Hunk_TempAlloc (0, size);
|
||||
if (!finalverts)
|
||||
Sys_Error ("R_AliasDrawModel: out of memory");
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ sw32_R_Textures_Init (void)
|
|||
|
||||
// create a simple checkerboard texture for the default
|
||||
r_notexture_mip =
|
||||
Hunk_AllocName (sizeof (texture_t) + 16 * 16 + 8 * 8 + 4 * 4 + 2 * 2,
|
||||
Hunk_AllocName (0, sizeof (texture_t) + 16 * 16 + 8 * 8 + 4 * 4 + 2 * 2,
|
||||
"notexture");
|
||||
|
||||
r_notexture_mip->width = r_notexture_mip->height = 16;
|
||||
|
@ -205,7 +205,8 @@ sw32_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
|
|||
r_cnumsurfs = MINSURFACES;
|
||||
|
||||
if (r_cnumsurfs > NUMSTACKSURFACES) {
|
||||
sw32_surfaces = Hunk_AllocName (r_cnumsurfs * sizeof (surf_t), "surfaces");
|
||||
sw32_surfaces = Hunk_AllocName (0, r_cnumsurfs * sizeof (surf_t),
|
||||
"surfaces");
|
||||
|
||||
sw32_surface_p = sw32_surfaces;
|
||||
sw32_surf_max = &sw32_surfaces[r_cnumsurfs];
|
||||
|
@ -228,7 +229,8 @@ sw32_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
|
|||
if (sw32_r_numallocatededges <= NUMSTACKEDGES) {
|
||||
sw32_auxedges = NULL;
|
||||
} else {
|
||||
sw32_auxedges = Hunk_AllocName (sw32_r_numallocatededges * sizeof (edge_t),
|
||||
sw32_auxedges = Hunk_AllocName (0,
|
||||
sw32_r_numallocatededges * sizeof (edge_t),
|
||||
"edges");
|
||||
}
|
||||
|
||||
|
@ -839,7 +841,7 @@ sw32_R_RenderView (void)
|
|||
if (delta < -10000 || delta > 10000)
|
||||
Sys_Error ("R_RenderView: called without enough stack");
|
||||
|
||||
if (Hunk_LowMark () & 3)
|
||||
if (Hunk_LowMark (0) & 3)
|
||||
Sys_Error ("Hunk is missaligned");
|
||||
|
||||
if ((intptr_t) (&dummy) & 3)
|
||||
|
|
|
@ -315,7 +315,7 @@ CL_NewMap (const char *mapname)
|
|||
{
|
||||
r_funcs->R_NewMap (cl.worldmodel, cl.model_precache, cl.nummodels);
|
||||
Con_NewMap ();
|
||||
Hunk_Check (); // make sure nothing is hurt
|
||||
Hunk_Check (0); // make sure nothing is hurt
|
||||
Sbar_CenterPrint (0);
|
||||
|
||||
if (cl.model_precache[1] && cl.model_precache[1]->brush.entities) {
|
||||
|
@ -365,7 +365,7 @@ CL_ParseServerInfo (void)
|
|||
Sys_Printf ("Bad maxclients (%u) from server\n", cl.maxclients);
|
||||
goto done;
|
||||
}
|
||||
cl.players = Hunk_AllocName (cl.maxclients * sizeof (*cl.players),
|
||||
cl.players = Hunk_AllocName (0, cl.maxclients * sizeof (*cl.players),
|
||||
"players");
|
||||
for (i = 0; i < cl.maxclients; i++) {
|
||||
cl.players[i].userinfo = Info_ParseString ("name\\", 0, 0);
|
||||
|
@ -444,7 +444,7 @@ CL_ParseServerInfo (void)
|
|||
dstring_clearstr (centerprint);
|
||||
CL_NewMap (model_precache[1]);
|
||||
|
||||
Hunk_Check (); // make sure nothing is hurt
|
||||
Hunk_Check (0); // make sure nothing is hurt
|
||||
|
||||
noclip_anglehack = false; // noclip is turned off at start
|
||||
r_data->gravity = 800.0; // Set up gravity for renderer effects
|
||||
|
|
|
@ -242,7 +242,7 @@ Host_FindMaxClients (void)
|
|||
if (svs.maxclientslimit < 4)
|
||||
svs.maxclientslimit = 4;
|
||||
svs.clients =
|
||||
Hunk_AllocName (svs.maxclientslimit * sizeof (client_t), "clients");
|
||||
Hunk_AllocName (0, svs.maxclientslimit * sizeof (client_t), "clients");
|
||||
|
||||
if (svs.maxclients > 1)
|
||||
Cvar_SetValue (deathmatch, 1.0);
|
||||
|
@ -499,7 +499,7 @@ Host_ClearMemory (void)
|
|||
CL_ClearMemory ();
|
||||
Mod_ClearAll ();
|
||||
if (host_hunklevel)
|
||||
Hunk_FreeToLowMark (host_hunklevel);
|
||||
Hunk_FreeToLowMark (0, host_hunklevel);
|
||||
|
||||
cls.signon = 0;
|
||||
memset (&sv, 0, sizeof (sv));
|
||||
|
@ -907,8 +907,8 @@ Host_Init (void)
|
|||
|
||||
COM_ExecConfig (host_cbuf, isDedicated || !cl_quakerc->int_val);
|
||||
|
||||
Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
|
||||
host_hunklevel = Hunk_LowMark ();
|
||||
Hunk_AllocName (0, 0, "-HOST_HUNKLEVEL-");
|
||||
host_hunklevel = Hunk_LowMark (0);
|
||||
|
||||
Sys_Printf ("\nVersion %s (build %04d)\n\n", PACKAGE_VERSION,
|
||||
build_number ());
|
||||
|
|
|
@ -493,7 +493,7 @@ convert_to_game_dict (script_t *script)
|
|||
PL_A_AddObject (item, PL_NewString (script->token->str));
|
||||
//char *s;
|
||||
|
||||
//s = Hunk_Alloc (strlen (script->token->str) + 1);
|
||||
//s = Hunk_Alloc (0, strlen (script->token->str) + 1);
|
||||
//strcpy (s, script->token->str);
|
||||
//sv.lightstyles[i] = s;
|
||||
}
|
||||
|
@ -687,7 +687,7 @@ Host_Loadgame_f (void)
|
|||
break;
|
||||
item = PL_ObjectAtIndex (list, i);
|
||||
style = PL_String (item);
|
||||
sv.lightstyles[i] = str = Hunk_Alloc (strlen (style) + 1);
|
||||
sv.lightstyles[i] = str = Hunk_Alloc (0, strlen (style) + 1);
|
||||
strcpy (str, style);
|
||||
}
|
||||
|
||||
|
@ -803,7 +803,7 @@ Host_Say (qboolean teamonly)
|
|||
|
||||
save = host_client;
|
||||
|
||||
p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1);
|
||||
p = Hunk_TempAlloc (0, strlen (Cmd_Args (1)) + 1);
|
||||
strcpy (p, Cmd_Args (1));
|
||||
// remove quotes if present
|
||||
if (*p == '"') {
|
||||
|
@ -869,7 +869,7 @@ Host_Tell_f (void)
|
|||
strcpy (text, host_client->name);
|
||||
strcat (text, ": ");
|
||||
|
||||
p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1);
|
||||
p = Hunk_TempAlloc (0, strlen (Cmd_Args (1)) + 1);
|
||||
strcpy (p, Cmd_Args (1));
|
||||
|
||||
// remove quotes if present
|
||||
|
|
|
@ -448,9 +448,9 @@ SV_Push (edict_t *pusher, const vec3_t tmove, const vec3_t amove)
|
|||
VectorAdd (p_angles, amove, p_angles);
|
||||
SV_LinkEdict (pusher, false);
|
||||
|
||||
mark = Hunk_LowMark ();
|
||||
moved_edict = Hunk_Alloc (sv.num_edicts * sizeof (edict_t *));
|
||||
moved_from = Hunk_Alloc (sv.num_edicts * sizeof (vec_t));
|
||||
mark = Hunk_LowMark (0);
|
||||
moved_edict = Hunk_Alloc (0, sv.num_edicts * sizeof (edict_t *));
|
||||
moved_from = Hunk_Alloc (0, sv.num_edicts * sizeof (vec_t));
|
||||
|
||||
// see if any solid entities are inside the final position
|
||||
num_moved = 0;
|
||||
|
@ -550,10 +550,10 @@ SV_Push (edict_t *pusher, const vec3_t tmove, const vec3_t amove)
|
|||
VectorSubtract (m_angles, amove, m_angles);
|
||||
SV_LinkEdict (moved_edict[i], false);
|
||||
}
|
||||
Hunk_FreeToLowMark (mark);
|
||||
Hunk_FreeToLowMark (0, mark);
|
||||
return false;
|
||||
}
|
||||
Hunk_FreeToLowMark (mark);
|
||||
Hunk_FreeToLowMark (0, mark);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -769,7 +769,7 @@ do_precache (progs_t *pr, const char **cache, int max, const char *name,
|
|||
|
||||
PR_CheckEmptyString (pr, name);
|
||||
|
||||
s = Hunk_TempAlloc (strlen (name) + 1);
|
||||
s = Hunk_TempAlloc (0, strlen (name) + 1);
|
||||
for (i = 0; *name; i++, name++) {
|
||||
int c = (byte) *name;
|
||||
s[i] = tolower (c);
|
||||
|
@ -778,7 +778,7 @@ do_precache (progs_t *pr, const char **cache, int max, const char *name,
|
|||
|
||||
for (i = 0; i < MAX_SOUNDS; i++) {
|
||||
if (!cache[i]) {
|
||||
char *c = Hunk_Alloc (strlen (s) + 1);
|
||||
char *c = Hunk_Alloc (0, strlen (s) + 1);
|
||||
strcpy (c, s);
|
||||
cache[i] = c; // blah, const
|
||||
Sys_MaskPrintf (SYS_dev, "%s: %3d %s\n", func, i, s);
|
||||
|
|
|
@ -416,7 +416,7 @@ CL_ClearState (void)
|
|||
VID_ClearMemory ();
|
||||
Mod_ClearAll ();
|
||||
if (host_hunklevel) // FIXME: check this...
|
||||
Hunk_FreeToLowMark (host_hunklevel);
|
||||
Hunk_FreeToLowMark (0, host_hunklevel);
|
||||
|
||||
CL_ClearEnts ();
|
||||
CL_ClearTEnts ();
|
||||
|
@ -1812,8 +1812,8 @@ Host_Init (void)
|
|||
// make sure all + commands have been executed
|
||||
Cbuf_Execute_Stack (cl_cbuf);
|
||||
|
||||
Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
|
||||
host_hunklevel = Hunk_LowMark ();
|
||||
Hunk_AllocName (0, 0, "-HOST_HUNKLEVEL-");
|
||||
host_hunklevel = Hunk_LowMark (0);
|
||||
|
||||
Sys_Printf ("\nClient version %s (build %04d)\n\n", PACKAGE_VERSION,
|
||||
build_number ());
|
||||
|
|
|
@ -319,7 +319,7 @@ CL_NewMap (const char *mapname)
|
|||
r_funcs->R_NewMap (cl.worldmodel, cl.model_precache, cl.nummodels);
|
||||
Team_NewMap ();
|
||||
Con_NewMap ();
|
||||
Hunk_Check (); // make sure nothing is hurt
|
||||
Hunk_Check (0); // make sure nothing is hurt
|
||||
Sbar_CenterPrint (0);
|
||||
|
||||
if (cl.model_precache[1] && cl.model_precache[1]->brush.entities) {
|
||||
|
|
|
@ -183,7 +183,7 @@ CL_Color_f (void)
|
|||
static void
|
||||
skin_f (cvar_t *var)
|
||||
{
|
||||
char *s = Hunk_TempAlloc (strlen (var->string) + 1);
|
||||
char *s = Hunk_TempAlloc (0, strlen (var->string) + 1);
|
||||
QFS_StripExtension (var->string, s);
|
||||
Cvar_Set (var, s);
|
||||
Cvar_Info (var);
|
||||
|
|
|
@ -779,7 +779,7 @@ SV_ConSay (const char *prefix, client_t *client)
|
|||
if (Cmd_Argc () < 2)
|
||||
return;
|
||||
|
||||
p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1);
|
||||
p = Hunk_TempAlloc (0, strlen (Cmd_Args (1)) + 1);
|
||||
strcpy (p, Cmd_Args (1));
|
||||
if (*p == '"') {
|
||||
p++;
|
||||
|
|
|
@ -787,7 +787,7 @@ Demo_Init (void)
|
|||
demo_name = dstring_newstr ();
|
||||
demo_text = dstring_newstr ();
|
||||
|
||||
svs.demomem = Hunk_AllocName (size, "demo");
|
||||
svs.demomem = Hunk_AllocName (0, size, "demo");
|
||||
svs.demomemsize = size;
|
||||
demo_max_size = size - 0x80000;
|
||||
|
||||
|
|
|
@ -222,7 +222,8 @@ sv_alloc_vis_array (unsigned numleafs)
|
|||
unsigned size = SET_SIZE (numleafs - 1);
|
||||
|
||||
if (size > SET_DEFMAP_SIZE * SET_BITS) {
|
||||
set_t *sets = Hunk_Alloc (numleafs * (sizeof (set_t) + size / 8));
|
||||
set_t *sets = Hunk_Alloc (0,
|
||||
numleafs * (sizeof (set_t) + size / 8));
|
||||
unsigned words = size / SET_BITS;
|
||||
set_bits_t *bits = (set_bits_t *) (&sets[numleafs]);
|
||||
for (unsigned i = 0; i < numleafs; i++) {
|
||||
|
@ -232,7 +233,7 @@ sv_alloc_vis_array (unsigned numleafs)
|
|||
}
|
||||
return sets;
|
||||
} else {
|
||||
set_t *sets = Hunk_Alloc (numleafs * sizeof (set_t));
|
||||
set_t *sets = Hunk_Alloc (0, numleafs * sizeof (set_t));
|
||||
for (unsigned i = 0; i < numleafs; i++) {
|
||||
sets[i].size = size;
|
||||
sets[i].map = sets[i].defmap;
|
||||
|
@ -337,7 +338,7 @@ SV_SpawnServer (const char *server)
|
|||
sv_pr_state.null_bad = 0;
|
||||
|
||||
Mod_ClearAll ();
|
||||
Hunk_FreeToLowMark (host_hunklevel);
|
||||
Hunk_FreeToLowMark (0, host_hunklevel);
|
||||
|
||||
// wipe the entire per-level structure, but don't lose sv.recorders
|
||||
// or signon buffers (good thing we're not multi-threaded FIXME?)
|
||||
|
|
|
@ -2541,8 +2541,8 @@ SV_Init (void)
|
|||
SVR_Init ();
|
||||
Demo_Init ();
|
||||
|
||||
Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
|
||||
host_hunklevel = Hunk_LowMark ();
|
||||
Hunk_AllocName (0, 0, "-HOST_HUNKLEVEL-");
|
||||
host_hunklevel = Hunk_LowMark (0);
|
||||
|
||||
Cbuf_InsertText (sv_cbuf, "exec server.cfg\n");
|
||||
|
||||
|
|
|
@ -451,9 +451,9 @@ SV_Push (edict_t *pusher, const vec3_t tmove, const vec3_t amove)
|
|||
VectorAdd (p_angles, amove, p_angles);
|
||||
SV_LinkEdict (pusher, false);
|
||||
|
||||
mark = Hunk_LowMark ();
|
||||
moved_edict = Hunk_Alloc (sv.num_edicts * sizeof (edict_t *));
|
||||
moved_from = Hunk_Alloc (sv.num_edicts * sizeof (vec_t));
|
||||
mark = Hunk_LowMark (0);
|
||||
moved_edict = Hunk_Alloc (0, sv.num_edicts * sizeof (edict_t *));
|
||||
moved_from = Hunk_Alloc (0, sv.num_edicts * sizeof (vec_t));
|
||||
|
||||
// see if any solid entities are inside the final position
|
||||
num_moved = 0;
|
||||
|
@ -553,10 +553,10 @@ SV_Push (edict_t *pusher, const vec3_t tmove, const vec3_t amove)
|
|||
VectorSubtract (m_angles, amove, m_angles);
|
||||
SV_LinkEdict (moved_edict[i], false);
|
||||
}
|
||||
Hunk_FreeToLowMark (mark);
|
||||
Hunk_FreeToLowMark (0, mark);
|
||||
return false;
|
||||
}
|
||||
Hunk_FreeToLowMark (mark);
|
||||
Hunk_FreeToLowMark (0, mark);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -739,7 +739,7 @@ do_precache (progs_t *pr, const char **cache, int max, const char *name,
|
|||
|
||||
PR_CheckEmptyString (pr, name);
|
||||
|
||||
s = Hunk_TempAlloc (strlen (name) + 1);
|
||||
s = Hunk_TempAlloc (0, strlen (name) + 1);
|
||||
for (i = 0; *name; i++, name++) {
|
||||
int c = (byte) *name;
|
||||
s[i] = tolower (c);
|
||||
|
@ -748,7 +748,7 @@ do_precache (progs_t *pr, const char **cache, int max, const char *name,
|
|||
|
||||
for (i = 0; i < max; i++) {
|
||||
if (!cache[i]) {
|
||||
char *c = Hunk_Alloc (strlen (s) + 1);
|
||||
char *c = Hunk_Alloc (0, strlen (s) + 1);
|
||||
strcpy (c, s);
|
||||
cache[i] = c; // blah, const
|
||||
Sys_MaskPrintf (SYS_dev, "%s: %3d %s\n", func, i, s);
|
||||
|
|
|
@ -174,7 +174,7 @@ PF_substr (progs_t *pr)
|
|||
if (len > l)
|
||||
len = l;
|
||||
|
||||
tmp = Hunk_TempAlloc (len + 1);
|
||||
tmp = Hunk_TempAlloc (0, len + 1);
|
||||
strncpy (tmp, s, len);
|
||||
tmp[len] = 0;
|
||||
|
||||
|
|
|
@ -862,7 +862,7 @@ SV_Say (qboolean team)
|
|||
host_client->whensaid[host_client->whensaidhead] = realtime;
|
||||
}
|
||||
|
||||
p = Hunk_TempAlloc (strlen (Cmd_Args (1)) + 1);
|
||||
p = Hunk_TempAlloc (0, strlen (Cmd_Args (1)) + 1);
|
||||
strcpy (p, Cmd_Args (1));
|
||||
|
||||
if (*p == '"') {
|
||||
|
|
|
@ -91,7 +91,7 @@ bi_read (progs_t *pr)
|
|||
int res;
|
||||
char *buffer;
|
||||
|
||||
buffer = Hunk_TempAlloc (count);
|
||||
buffer = Hunk_TempAlloc (0, count);
|
||||
if (!buffer)
|
||||
PR_Error (pr, "%s: couldn't allocate %d bytes", "bi_read", count);
|
||||
res = read (handle, buffer, count);
|
||||
|
|
Loading…
Reference in a new issue