当前位置: 首页>>代码示例>>C++>>正文


C++ Q_malloc函数代码示例

本文整理汇总了C++中Q_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ Q_malloc函数的具体用法?C++ Q_malloc怎么用?C++ Q_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Q_malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GL_ResampleTexture

/*
================
GL_ResampleTexture
================
*/
void GL_ResampleTexture (unsigned *indata, int inwidth, int inheight,
		unsigned *outdata, int outwidth, int outheight)
{
	// _pixops_scale is too slow for large downsampling factors, so make use
	// of the fast GL_MipMap when possible
	if (inwidth >= outwidth*2 && inheight >= outheight*2) {
		int tw, th;
		byte *in, *buf;

		for (tw = outwidth, th = outheight; tw*2 <= inwidth && th*2 <= inheight; ) {
			tw *= 2;
			th *= 2;
		}

		if (inwidth > tw || inheight > th) {
			buf = Q_malloc (tw * th * 4);
			_pixops_scale ((guchar *)buf, 0, 0, tw, th, tw * 4, 4, 1, (const guchar *)indata,
				inwidth, inheight, inwidth * 4, 4, 1, (double)tw/inwidth, (double)th/inheight, PIXOPS_INTERP_BILINEAR);
			in = buf;
		} else {
			buf = Q_malloc ((tw/2) * (th/2) * 4);
			in = (byte *)indata;
		}

		while (tw > outwidth) {
			GL_MipMap (in, buf, tw, th);
			in = buf;
			tw >>= 1;
			th >>= 1;
		}

		memcpy (outdata, buf, outwidth*outheight*4);
		Q_free (buf);
		return;
	}
开发者ID:luaman,项目名称:zq,代码行数:40,代码来源:gl_texture.c

示例2: Host_InitVCR

void Host_InitVCR (quakeparms_t *parms)
{
	int		i, len, n;
	char	*p;

	if (COM_CheckParm("-playback"))
	{
		if (com_argc != 2)
			Sys_Error("No other parameters allowed with -playback\n");

		Sys_FileOpenRead("quake.vcr", &vcrFile);
		if (vcrFile == -1)
			Sys_Error("playback file not found\n");

		Sys_FileRead (vcrFile, &i, sizeof(int));
		if (i != VCR_SIGNATURE)
			Sys_Error("Invalid signature in vcr file\n");

		Sys_FileRead (vcrFile, &com_argc, sizeof(int));
		com_argv = Q_malloc(com_argc * sizeof(char *));
		com_argv[0] = parms->argv[0];
		for (i = 0; i < com_argc; i++)
		{
			Sys_FileRead (vcrFile, &len, sizeof(int));
			p = Q_malloc(len);
			Sys_FileRead (vcrFile, p, len);
			com_argv[i+1] = p;
		}
		com_argc++; /* add one for arg[0] */
		parms->argc = com_argc;
		parms->argv = com_argv;
	}

	if ( (n = COM_CheckParm("-record")) != 0)
	{
		vcrFile = Sys_FileOpenWrite("quake.vcr");

		i = VCR_SIGNATURE;
		Sys_FileWrite(vcrFile, &i, sizeof(int));
		i = com_argc - 1;
		Sys_FileWrite(vcrFile, &i, sizeof(int));
		for (i = 1; i < com_argc; i++)
		{
			if (i == n)
			{
				len = 10;
				Sys_FileWrite(vcrFile, &len, sizeof(int));
				Sys_FileWrite(vcrFile, "-playback", len);
				continue;
			}
			len = strlen(com_argv[i]) + 1;
			Sys_FileWrite(vcrFile, &len, sizeof(int));
			Sys_FileWrite(vcrFile, com_argv[i], len);
		}
	}

}
开发者ID:darkduke606,项目名称:Insomnia-ProQuake-Engine,代码行数:57,代码来源:host.c

示例3: XSD_RenderDocument

// renders document into memory buffer,
int XSD_RenderDocument(document_rendered_t *ret, xml_document_t *doc, int width)
{
    int lines;

    memset(ret, 0, sizeof(document_rendered_t));

    // render document title
    if (doc->title)
    {
        int lines;
        document_tag_text_t *text;
        document_tag_p_t *p;
        xml_document_t *tdoc;

        tdoc = XSD_Document_New();

        // create p tag
        p = (document_tag_p_t *) Q_malloc(sizeof(document_tag_p_t));
        memset(p, 0, sizeof(document_tag_p_t));
        p->type = tag_p;
        p->align = align_center;

        tdoc->content = (document_tag_t *) p;

        // create text tag
        text = (document_tag_text_t *) Q_malloc(sizeof(document_tag_text_t));
        memset(text, 0, sizeof(document_tag_text_t));
        text->type = tag_text;
        text->text = Q_strdup(doc->title);

        p->tags = (document_tag_t *) text;

        lines = XSD_RenderDocumentOnce(tdoc, NULL, width, 0, NULL, NULL);
        if (lines > 0)
        {
            ret->title = (char *) Q_malloc(lines*width);
	    ret->title_lines = XSD_RenderDocumentOnce(tdoc,(byte *) ret->title, width, lines, NULL, NULL);
        }

        XSD_Document_Free((xml_t *)tdoc);
    }

    // render document body
    lines = XSD_RenderDocumentOnce(doc, NULL, width, 0, NULL, NULL);
    if (lines <= 0)
        goto error;
    ret->text = (char *) Q_malloc(lines*width);
    ret->text_lines = XSD_RenderDocumentOnce(doc,(byte *) ret->text, width, lines, &ret->links, &ret->sections);
    return 1;

error:
    XSD_RenderClear(ret);
    return 0;
}
开发者ID:jogi1,项目名称:camquake,代码行数:55,代码来源:document_rendering.c

示例4: Cmd_StuffCmds_f

/*
===============
Cmd_StuffCmds_f

Adds command line parameters as script statements
Commands lead with a +, and continue until a - or another +
quake +prog jctest.qp +cmd amlev1
quake -nosound +cmd amlev1
===============
*/
void Cmd_StuffCmds_f (void)
{
	int i, j;
	int s;
	char *text, *build, c;

	// build the combined string to parse from
	s = 0;
	for (i = 1; i < com_argc; i++)
		s += strlen (com_argv[i]) + 1;

	if (!s)
		return;

	text = (char *) Q_malloc (s+1);
	text[0] = 0;
	for (i = 1; i < com_argc; i++)
	{
		strlcat (text, com_argv[i], s + 1);
		if (i != com_argc-1)
			strlcat (text, " ", s + 1);
	}

	// pull out the commands
	build = (char *) Q_malloc (s+1);
	build[0] = 0;

	for (i=0 ; i<s-1 ; i++)
	{
		if (text[i] == '+')
		{
			i++;

			for (j=i ; (text[j] != '+') && (text[j] != '-') && (text[j] != 0) ; j++)
				;

			c = text[j];
			text[j] = 0;

			strlcat (build, text + i, s + 1);
			strlcat (build, "\n", s + 1);
			text[j] = c;
			i = j-1;
		}
	}

	if (build[0])
		Cbuf_AddText (build);

	Q_free (text);
	Q_free (build);
}
开发者ID:QuakePhil,项目名称:mvdsv,代码行数:62,代码来源:cmd.c

示例5: Precache_Source

static void Precache_Source(source_data *s)
{
    int i;
    char name[1024];
    server_data *servers[MAX_SERVERS];
    int serversn = 0;

	if (s->type == type_url) {
		char *filename;
		size_t filename_size = SB_URL_To_Filename_Length(s->address.url);

		filename = Q_malloc(filename_size);
		SB_URL_to_FileName(s->address.url, filename, filename_size);
		snprintf(name, sizeof (name), "sb/cache/%s", filename);
		Q_free(filename);
	}
	else if (s->type == type_master) {
		snprintf(name, sizeof (name), "sb/cache/%d_%d_%d_%d_[%d].txt",
				s->address.address.ip[0], s->address.address.ip[1],
				s->address.address.ip[2], s->address.address.ip[3],
				ntohs(s->address.address.port));
	}
	else {
		return;
	}

	Update_Source_From_File(s, name, servers, &serversn);

	if (serversn > 0)
	{
		SYSTEMTIME tm;
		char tmp_path[MAX_OSPATH] = {0};

		snprintf(&tmp_path[0], sizeof(tmp_path), "%s/ezquake/%s", com_basedir, name);
		if (GetFileLocalTime(tmp_path, &tm))
		{
			Reset_Source(s);
			s->servers = (server_data **) Q_malloc(serversn * sizeof(server_data *));
			for (i=0; i < serversn; i++)
				s->servers[i] = servers[i];
			s->serversn = serversn;
			s->servers_allocated = serversn;

			if (s->checked)
				rebuild_servers_list = 1;

			memcpy(&s->last_update, &tm, sizeof(SYSTEMTIME));
		}
	}
}
开发者ID:eb,项目名称:ezquake-source,代码行数:50,代码来源:EX_browser_sources.c

示例6: Cvar_Find

/*
===========
Cvar_Get
===========
*/
cvar_t *Cvar_Get (const char *name, const char *string, int cvarflags)
{
	cvar_t		*var;
	int			key;

	var = Cvar_Find(name);
	if (var) {
		var->flags &= ~CVAR_TEMP;
		var->flags |= cvarflags;
		return var;
	}

	// allocate a new cvar
	var = (cvar_t *) Q_malloc (sizeof(cvar_t));

	// link it in
	var->next = cvar_vars;
	cvar_vars = var;
	key = Com_HashKey (name);
	var->hash_next = cvar_hash[key];
	cvar_hash[key] = var;

	// Q_malloc returns unitialized memory, so make sure all fields
	// are initialized here
	var->name = Q_strdup (name);
	var->string = Q_strdup (string);
	var->flags = cvarflags | CVAR_DYNAMIC;
	var->value = Q_atof (var->string);
	var->OnChange = NULL;

	// FIXME, check userinfo/serverinfo

	return var;
}
开发者ID:luaman,项目名称:zq,代码行数:39,代码来源:cvar.cpp

示例7: Q_malloc

// allocate, may link it in, if requested
svtcpstream_t *sv_tcp_connection_new(int sock, netadr_t from, char *buf, int buf_len, qbool link)
{
	svtcpstream_t *st = NULL;

	st = Q_malloc(sizeof(svtcpstream_t));
	st->waitingforprotocolconfirmation = true;
	st->socketnum = sock;
	st->remoteaddr = from;
	if (buf_len > 0 && buf_len < sizeof(st->inbuffer))
	{
		memmove(st->inbuffer, buf, buf_len);
		st->inlen = buf_len;
	}
	else
		st->drop = true; // yeah, funny

	// link it in if requested
	if (link)
	{
		st->next = svs.tcpstreams;
		svs.tcpstreams = st;
	}

	return st;
}
开发者ID:DavidWiberg,项目名称:ezquake-source,代码行数:26,代码来源:net.c

示例8: strlen

// adds text element
char *Add_Inline_Text (document_rendering_context_t *cx, char *text, document_tag_text_t *tag)
{
	char *s, *d;
	char *buf;
	size_t size;

	size = strlen (text) + strlen (tag->text) + 1;
	buf = (char *) Q_malloc (size);
	strlcpy (buf, text, size);
	Q_free (text);

	d = buf + strlen(buf);
	s = tag->text;

	while (*s)
	{
		char c = *s++;

		if (cx->do_color)
			c = ChangeColor(c);

		*d++ = c;
	}

	*d = 0;

	return buf;
}
开发者ID:jogi1,项目名称:camquake,代码行数:29,代码来源:document_rendering.c

示例9: Q_malloc

// strip spaces multiple spaces from in-between words
char *XSD_StripSpaces (char *str)
{
    char *buf, *ret;
    unsigned int p = 0, q = 0;

    if (str == NULL)
        return str;

    buf = (char *) Q_malloc(strlen(str)+1);
    for (p=0; p < strlen(str); p++)
    {
        if (XSD_IsSpace(str[p]))
        {
            if (q == 0  ||  XSD_IsSpace(buf[q-1]))
                ;
            else
                buf[q++] = ' ';
        }
        else
            buf[q++] = str[p];
    }

    // strip spaces from the end
    while (q > 0  &&  XSD_IsSpace(buf[q-1]))
        q--;
    buf[q] = 0;

    ret = (char *) Q_strdup(buf);
    Q_free(buf);
    Q_free(str);
    return ret;
}
开发者ID:AAS,项目名称:ezquake-source,代码行数:33,代码来源:xsd.c

示例10: Q_malloc

cvar_t *Cvar_Create (char *name, char *string, int cvarflags)
{
	cvar_t *v;
	int key;

	if ((v = Cvar_Find(name))) {
		v->flags &= ~CVAR_TEMP;
		v->flags |= cvarflags;
		return v;
	}
	v = (cvar_t *) Q_malloc(sizeof(cvar_t));
	memset(v, 0, sizeof(cvar_t));
	// Cvar doesn't exist, so we create it
	v->next = cvar_vars;
	cvar_vars = v;

	key = Com_HashKey (name) % VAR_HASHPOOL_SIZE;
	v->hash_next = cvar_hash[key];
	cvar_hash[key] = v;

	v->name = Q_strdup(name);
	v->string = Q_strdup(string);
	v->defaultvalue = Q_strdup(string);
	v->flags = cvarflags | CVAR_USER_CREATED;
	v->value = Q_atof (v->string);
	v->integer = Q_atoi (v->string);
	StringToRGB_W(v->string, v->color);
	v->modified = true;
#ifdef WITH_TCL
	TCL_RegisterVariable (v);
#endif

	return v;
}
开发者ID:javian,项目名称:ezquake-source,代码行数:34,代码来源:cvar.c

示例11: MP3_WINAMP_CachePlaylist

int MP3_WINAMP_CachePlaylist(void) {
	char *playlist_buf;
	unsigned int length;
	int current;

	if ((length = WINAMP_GetPlaylist(&playlist_buf)) == -1) 
	{
		Com_Printf("%s is not running\n", mp3_player->PlayerName_LeadingCaps);
		return -1;
	}

	MP3_WINAMP_GetPlaylistInfo(&current, &WINAMP_Playlist_nelms);

	/* Free the list before we cache a new one */
	if (WINAMP_Playlist) {
		MP3_WINAMP_CachePlaylistFlush();
	}

	WINAMP_Playlist = (char **) Q_malloc(sizeof(*WINAMP_Playlist)*WINAMP_Playlist_nelms);

	WINAMP_Playlist_nelms = WINAMP_ParsePlaylist_EXTM3U(playlist_buf, length, 
									WINAMP_Playlist, WINAMP_Playlist_nelms);

	Q_free(playlist_buf);

	return 0;
}
开发者ID:jogi1,项目名称:camquake,代码行数:27,代码来源:mp3_winamp.c

示例12: CPageViewer_New

CPageViewer_t * CPageViewer_New(void)
{
    CPageViewer_t *viewer = (CPageViewer_t *) Q_malloc(sizeof(CPageViewer_t));

    CPageViewer_Init(viewer);
    return viewer;
}
开发者ID:AAS,项目名称:ezquake-source,代码行数:7,代码来源:Ctrl_PageViewer.c

示例13: AddToFileSource

void AddToFileSource(source_data *source, server_data *serv)
{
	if (IsInSource(source, serv))
		return;

	SB_ServerList_Lock();

    // reallocate buffer if we've run out of space
	if (source->serversn >= source->servers_allocated) {
		int new_size = source->servers_allocated + 4;
		server_data** newlist = Q_malloc(new_size * sizeof(server_data*));

		memcpy(newlist, source->servers, sizeof(server_data*) * source->servers_allocated);
		Q_free(source->servers);
		source->servers = newlist;
		source->servers_allocated = new_size;
	}

	source->servers[source->serversn++] = Clone_Server(serv);
	rebuild_servers_list = true;

	SB_ServerList_Unlock();

	DumpSource(source);
	Mark_Source(sources[0]);
}
开发者ID:eb,项目名称:ezquake-source,代码行数:26,代码来源:EX_browser_sources.c

示例14: QTV_UserById

// allocate data and set fields, perform linkage to qtvuserlist
// Well, instead of QTV_NewUser(int id, char *name, ...) I pass params with single qtvuser_t *user struct, well its OK for current struct.
static qtvuser_t *QTV_NewUser(qtvuser_t *user)
{
	// check, may be user alredy exist, so reuse it
	qtvuser_t *newuser = QTV_UserById(user->id);

	if (!newuser)
	{
		// user does't exist, alloc data
		newuser = Q_malloc(sizeof(*newuser));

		QTV_SetUser(newuser, user);

		// perform linkage
		newuser->next = qtvuserlist;
		qtvuserlist = newuser;
	}
	else
	{
		// we do not need linkage, just save current
		qtvuser_t *oldnext = newuser->next; // we need save this before assign all fields

		QTV_SetUser(newuser, user);

		newuser->next = oldnext;
	}

	return newuser;
}
开发者ID:DavidWiberg,项目名称:ezquake-source,代码行数:30,代码来源:qtv.c

示例15: MVD_ClockStart

void MVD_ClockStart(int itemtype)
{
	mvd_clock_t *newclock = (mvd_clock_t *) Q_malloc(sizeof (mvd_clock_t));
	newclock->clockval = cls.demotime + MVD_RespawnTimeGet(itemtype);
	newclock->itemtype = itemtype;
	MVD_ClockList_Insert(newclock);
}
开发者ID:DavidWiberg,项目名称:ezquake-source,代码行数:7,代码来源:mvd_utils.c


注:本文中的Q_malloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。