• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ Q_malloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: SaveConfig

void SaveConfig(const char *cfgname)
{
	char filename[MAX_PATH] = {0}, *filename_ext, *backupname_ext;
	size_t len;
	FILE *f;

	snprintf(filename, sizeof(filename) - 4, "%s", cfgname[0] ? cfgname : MAIN_CONFIG_FILENAME); // use config.cfg if no params was specified

	COM_ForceExtensionEx (filename, ".cfg", sizeof (filename));

	if (cfg_backup.integer) {
		if (cfg_use_home.integer)	// homedir
			filename_ext = va("%s/%s/%s", com_homedir, (strcmp(com_gamedirfile, "qw") == 0 || !cfg_use_gamedir.integer) ? "" : com_gamedirfile, filename);
		else	// basedir
			filename_ext = va("%s/%s/configs/%s", com_basedir, (strcmp(com_gamedirfile, "qw") == 0 || !cfg_use_gamedir.integer) ? "ezquake" : com_gamedirfile, filename);

		if ((f = fopen(filename_ext, "r"))) {
			fclose(f);
			len = strlen(filename_ext) + 5;
			backupname_ext = (char *) Q_malloc(len);
			snprintf (backupname_ext, len, "%s.bak", filename_ext);

			if ((f = fopen(backupname_ext, "r"))) {
				fclose(f);
				remove(backupname_ext);
			}

			rename(filename_ext, backupname_ext);
			Q_free(backupname_ext);
		}
	}

	DumpConfig(filename);
	filesystemchanged = true; // fix bug 2359900
}
开发者ID:JosephPecoraro,项目名称:ezquake-source,代码行数:35,代码来源:config_manager.c


示例17: Cvar_AddGroup

static cvar_group_t *Cvar_AddGroup(char *name)
{
	static qbool initialised = false;
	cvar_group_t *newgroup;
	char **s;

	if (!initialised) {
		initialised = true;
		for (s = cvar_groups_list; *s; s++)
			Cvar_AddGroup(*s);
	}

	for (newgroup = cvar_groups; newgroup; newgroup = newgroup->next)
		if (!strcasecmp(newgroup->name, name))
			return newgroup;

	newgroup = (cvar_group_t *) Q_malloc(sizeof(cvar_group_t));
	strlcpy(newgroup->name, name, sizeof(newgroup->name));
	newgroup->count = 0;
	newgroup->head = NULL;
	newgroup->next = cvar_groups;
	cvar_groups = newgroup;

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


示例18: RenderDocument

static void RenderDocument(CPageViewer_t *viewer, int width)
{
    // int lines;
    xml_document_t *doc;

    LeaveNavigationMode(viewer);
    FreePageRendered(viewer->page);

    viewer->page->current_line = 0;
    viewer->page->width = width;
    viewer->page->should_render = false;

    // load document
    if (!viewer->page->doc)
        viewer->page->doc = XSD_LoadDocumentWithXsl(viewer->page->url);

    if (!viewer->page->doc)
        goto error;

    doc = viewer->page->doc;

    if (!XSD_RenderDocument(&viewer->page->rendered, doc, width))
        goto error;

    return;

error:

    viewer->page->rendered.title = (char *) Q_malloc(viewer->page->width);
    memset(viewer->page->rendered.title, 0, width);
    memcpy(viewer->page->rendered.title, "Document loading error!", strlen("Document loading error!"));
    viewer->page->rendered.title_lines = 1;
    return;
}
开发者ID:AAS,项目名称:ezquake-source,代码行数:34,代码来源:Ctrl_PageViewer.c


示例19: AddPage

static void AddPage(CPageViewer_t *viewer)
{
    CPageViewer_page_t *page = (CPageViewer_page_t *) Q_malloc(sizeof(CPageViewer_page_t));
    memset(page, 0, sizeof(CPageViewer_page_t));

    page->next = viewer->page;
    viewer->page = page;
}
开发者ID:AAS,项目名称:ezquake-source,代码行数:8,代码来源:Ctrl_PageViewer.c


示例20: Q_malloc

// returns Q_malloc'ed data
wchar *decode_cp1251 (char *str) {
	wchar *buf, *out;
	buf = out = Q_malloc ((strlen(str) + 1)*sizeof(wchar));
	while (*str)
		*out++ = cp1251towc(*str++);
	*out = 0;
	return buf;
};
开发者ID:jogi1,项目名称:camquake,代码行数:9,代码来源:textencoding.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Q_memcpy函数代码示例发布时间:2022-05-30
下一篇:
C++ Q_irand函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap