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


C++ d_malloc函数代码示例

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


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

示例1: hashtable_init

int hashtable_init( hashtable *ht, int size )	{
	int i;

	ht->size=0;

	for (i=1; i<13; i++ )	{
		if ( (1<<i) >= size )	{
			ht->bitsize = i;
			ht->size = 1<<i;
			break;
		}
	}
	size = ht->size;
	ht->and_mask = ht->size - 1;
	if (ht->size==0)
		Error( "Hashtable has size of 0" );

	ht->key = d_malloc( size * sizeof(char *) );
	if (ht->key==NULL)
		Error( "Not enough memory to create a hash table of size %d", size );

	for (i=0; i<size; i++ )
		ht->key[i] = NULL;

	// Use calloc cause we want zero'd array.
	ht->value = d_malloc( size*sizeof(int) );
	if (ht->value==NULL)	{
		d_free(ht->key);
		Error( "Not enough memory to create a hash table of size %d\n", size );
	}

	ht->nitems = 0;

	return 0;
}
开发者ID:btb,项目名称:d2x,代码行数:35,代码来源:hash.c

示例2: d_error_new

DError* d_error_new(int level,const char* file,int line, const char* msg,...){
    
    char* buffer;
    
    DError* error = (DError*)d_malloc(sizeof(DError));
    error->level = level;
    
    if ( msg == NULL){
        error->msg = NULL;
    }
    else {
        error->file = d_strdup(file);
        error->line = line;
        
        va_list args;
        va_start(args,msg);
        int count = vsnprintf(buffer,0,msg,args);
        va_end(args);
        buffer = d_malloc(sizeof(char)*count+1);
        
        va_list args2;
        va_start(args2,msg);
        vsnprintf(buffer,count+1,msg,args2);
        va_end(args2);
        
        error->msg = buffer;
        
    }
    
    return error;
}
开发者ID:drolland,项目名称:DGK,代码行数:31,代码来源:d_error.c

示例3: align_polygon_model_data

void align_polygon_model_data(polymodel *pm)
{
	int i, chunk_len;
	int total_correction = 0;
	ubyte *cur_old, *cur_new;
	chunk cur_ch;
	chunk ch_list[MAX_CHUNKS];
	int no_chunks = 0;
	int tmp_size = pm->model_data_size + SHIFT_SPACE;
	ubyte *tmp = d_malloc(tmp_size); // where we build the aligned version of pm->model_data

	Assert(tmp != NULL);
	//start with first chunk (is always aligned!)
	cur_old = pm->model_data;
	cur_new = tmp;
	chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
	memcpy(cur_new, cur_old, chunk_len);
	while (no_chunks > 0) {
		int first_index = get_first_chunks_index(ch_list, no_chunks);
		cur_ch = ch_list[first_index];
		// remove first chunk from array:
		no_chunks--;
		for (i = first_index; i < no_chunks; i++)
			ch_list[i] = ch_list[i + 1];
		// if (new) address unaligned:
		if ((u_int32_t)new_dest(cur_ch) % 4L != 0) {
			// calculate how much to move to be aligned
			short to_shift = 4 - (u_int32_t)new_dest(cur_ch) % 4L;
			// correct chunks' addresses
			cur_ch.correction += to_shift;
			for (i = 0; i < no_chunks; i++)
				ch_list[i].correction += to_shift;
			total_correction += to_shift;
			Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
			Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
		}
		//write (corrected) chunk for current chunk:
		*((short *)(cur_ch.new_base + cur_ch.offset))
		  = INTEL_SHORT(cur_ch.correction
				+ INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset))));
		//write (correctly aligned) chunk:
		cur_old = old_dest(cur_ch);
		cur_new = new_dest(cur_ch);
		chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
		memcpy(cur_new, cur_old, chunk_len);
		//correct submodel_ptr's for pm, too
		for (i = 0; i < MAX_SUBMODELS; i++)
			if (pm->model_data + pm->submodel_ptrs[i] >= cur_old
			    && pm->model_data + pm->submodel_ptrs[i] < cur_old + chunk_len)
				pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data);
 	}
	d_free(pm->model_data);
	pm->model_data_size += total_correction;
	pm->model_data = 
	d_malloc(pm->model_data_size);
	Assert(pm->model_data != NULL);
	memcpy(pm->model_data, tmp, pm->model_data_size);
	d_free(tmp);
}
开发者ID:CDarrow,项目名称:DXX-Retro,代码行数:59,代码来源:polyobj.c

示例4: audio_data_handler

static int audio_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
#ifdef AUDIO
	static const int selected_chan=1;
	int chan;
	int nsamp;
	if (mve_audio_canplay)
	{
		if (mve_audio_playing)
			SDL_LockAudio();

		chan = get_ushort(data + 2);
		nsamp = get_ushort(data + 4);
		if (chan & selected_chan)
		{
			/* HACK: +4 mveaudio_uncompress adds 4 more bytes */
			if (major == MVE_OPCODE_AUDIOFRAMEDATA) {
				if (mve_audio_compressed) {
					nsamp += 4;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp);
					mveaudio_uncompress(mve_audio_buffers[mve_audio_buftail], data, -1); /* XXX */
				} else {
					nsamp -= 8;
					data += 8;

					mve_audio_buflens[mve_audio_buftail] = nsamp;
					mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp);
					memcpy(mve_audio_buffers[mve_audio_buftail], data, nsamp);
				}
			} else {
				mve_audio_buflens[mve_audio_buftail] = nsamp;
				mve_audio_buffers[mve_audio_buftail] = (short *)d_malloc(nsamp);

				memset(mve_audio_buffers[mve_audio_buftail], 0, nsamp); /* XXX */
			}

			if (++mve_audio_buftail == TOTAL_AUDIO_BUFFERS)
				mve_audio_buftail = 0;

			if (mve_audio_buftail == mve_audio_bufhead)
				fprintf(stderr, "d'oh!  buffer ring overrun (%d)\n", mve_audio_bufhead);
		}

		if (mve_audio_playing)
			SDL_UnlockAudio();
	}
#endif

	return 1;
}
开发者ID:gameplayer22,项目名称:d2x-1,代码行数:52,代码来源:mveplay.c

示例5: cfopen

CFILE * cfopen(char * filename, char * mode )
{
	int length;
	FILE * fp;
	CFILE *cfile;

	if (stricmp( mode, "rb"))	{
		Error( "cfiles can only be opened with mode==rb\n" );
	}

	if (filename[0] != '\x01') {
		#ifdef MACINTOSH
		char mac_path[255];

		macify_dospath(filename, mac_path);
		fp = cfile_get_filehandle( mac_path, mode);
		#else
		fp = cfile_get_filehandle( filename, mode );		// Check for non-hog file first...
		#endif
	} else {
		fp = NULL;		//don't look in dir, only in hogfile
		filename++;
	}

	if ( !fp ) {
		fp = cfile_find_libfile(filename, &length );
		if ( !fp )
			return NULL;		// No file found
		cfile = d_malloc ( sizeof(CFILE) );
		if ( cfile == NULL ) {
			fclose(fp);
			return NULL;
		}
		cfile->file = fp;
		cfile->size = length;
		cfile->lib_offset = ftell( fp );
		cfile->raw_position = 0;
		return cfile;
	} else {
		cfile = d_malloc ( sizeof(CFILE) );
		if ( cfile == NULL ) {
			fclose(fp);
			return NULL;
		}
		cfile->file = fp;
		cfile->size = filelength( fileno(fp) );
		cfile->lib_offset = 0;
		cfile->raw_position = 0;
		return cfile;
	}
}
开发者ID:gameplayer22,项目名称:d2x-1,代码行数:51,代码来源:cfile.c

示例6: CreateSphere

int CreateSphere (tOOF_vector **pSphere)
{
    int			nFaces, i, j;
    tOOF_vector	*buf [2];

    if (gameData.render.sphere.nFaceNodes == 3) {
        nFaces = 8;
        j = 6;
    }
    else {
        nFaces = 6;
        j = 4;
    }
    for (i = 0; i < gameData.render.sphere.nTessDepth; i++)
        nFaces *= j;
    for (i = 0; i < 2; i++) {
        if (!(buf [i] = (tOOF_vector *) d_malloc (nFaces * (gameData.render.sphere.nFaceNodes + 1) * sizeof (tOOF_vector)))) {
            if (i)
                d_free (buf [i - 1]);
            return -1;
        }
    }
    j = (gameData.render.sphere.nFaceNodes == 3) ?
        BuildSphereTri ((tOOF_triangle **) buf, &nFaces) :
        BuildSphereQuad ((tOOF_quad **) buf, &nFaces);
    d_free (buf [!j]);
    *pSphere = buf [j];
    return nFaces;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:29,代码来源:sphere.c

示例7: save_screen_shot

void save_screen_shot(int automap_flag)
{
	static int savenum=0;
	char savename[13+sizeof(SCRNS_DIR)];
	unsigned char *buf;

	if (!GameArg.DbgGlReadPixelsOk){
		if (!automap_flag)
			HUD_init_message_literal(HM_DEFAULT, "glReadPixels not supported on your configuration");
		return;
	}

	stop_time();

	if (!PHYSFSX_exists(SCRNS_DIR,0))
		PHYSFS_mkdir(SCRNS_DIR); //try making directory

	do
	{
		sprintf(savename, "%sscrn%04d.tga",SCRNS_DIR, savenum++);
	} while (PHYSFSX_exists(savename,0));

	if (!automap_flag)
		HUD_init_message(HM_DEFAULT, "%s 'scrn%04d.tga'", TXT_DUMPING_SCREEN, savenum-1 );

#ifndef OGLES
	glReadBuffer(GL_FRONT);
#endif

	buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
	write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);
	d_free(buf);

	start_time();
}
开发者ID:CDarrow,项目名称:DXX-Retro,代码行数:35,代码来源:gr.c

示例8: d_tableNew

d_table
d_tableNew(
    int ( *  compare )(),
    void ( * cleanAction )() )
{
    d_table table;

    assert(compare != 0);
    /* Allocate table object */
    table = (d_table)d_malloc(C_SIZEOF(d_table), "Table");
    if (table) {
        /* QAC EXPECT 3892; */
        /* Call super-init */
        d_objectInit(d_object(table), D_TABLE,
                     (d_objectDeinitFunc)d_tableDeinit);
        /* Initialize table object */
        ut_avlCTreedefInit (&table->td,
                            offsetof (C_STRUCT(d_tableNode), avlnode), offsetof (C_STRUCT(d_tableNode), object),
                            (int (*) (const void *, const void *)) compare, 0,
                            UT_AVL_TREEDEF_FLAG_INDKEY);
        ut_avlCInit (&table->td, &table->tree);
        table->cleanAction = cleanAction;
    }
    return table;
}
开发者ID:osrf,项目名称:opensplice,代码行数:25,代码来源:d_table.c

示例9: DigiSpeedupSound

int DigiSpeedupSound (digi_sound *gsp, struct sound_slot *ssp, int speed)
{
    int	h, i, j, l;
    ubyte	*pDest, *pSrc;

    l = FixMulDiv (ssp->bResampled ? ssp->length : gsp->length, speed, F1_0);
    if (!(pDest = (ubyte *) d_malloc (l)))
        return -1;
    pSrc = ssp->bResampled ? ssp->samples : gsp->data;
    for (h = i = j = 0; i < l; i++) {
        pDest [j] = pSrc [i];
        h += speed;
        while (h >= F1_0) {
            j++;
            h -= F1_0;
        }
    }
    if (ssp->bResampled)
    {
        d_free (ssp->samples);
    }
    else
        ssp->bResampled = 1;
    ssp->samples = pDest;
    return ssp->length = j;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:26,代码来源:digi.c

示例10: splitword

char* splitword(char *s, char splitchar)
{
 int x,l,l2;
 char *word;

   for(l=0;s[l]!=0;l++);
   for(x=0;s[x]!=splitchar&&x<l;x++);
  l2=x;
  s[x]=0;
  word = (char *) d_malloc(sizeof(char) * (l2+1));
   for(x=0;x<=l2;x++)
    word[x]=s[x];

   if(l==l2)
    s[0]=0;
   else
    {
     while(x<=l)
      {
       s[x-l2-1]=s[x];
       x++;
      }
    }
  return word;
}
开发者ID:CDarrow,项目名称:DXX-Retro,代码行数:25,代码来源:strio.c

示例11: create_new_mission

void create_new_mission(void)
{
	if (Current_mission)
		free_mission();
	
	Current_mission = d_malloc(sizeof(Mission));
	if (!Current_mission)
		return;
	memset(Current_mission, 0, sizeof(Mission));
	
	Current_mission->path = d_strdup("new_mission");
	if (!Current_mission->path)
	{
		free_mission();
		return;
	}

	Current_mission->filename = Current_mission->path;
	
	MALLOC(Level_names, d_fname, 1);
	if (!Level_names)
	{
		free_mission();
		return;
	}

	strcpy(Level_names[0], "GAMESAVE.LVL");
}
开发者ID:CDarrow,项目名称:DXX-Retro,代码行数:28,代码来源:mission.c

示例12: f_list_init

struct s_list *f_keys_initialize(struct s_list *supplied, const char *file, char separator) {
	struct s_list *result = supplied;
	struct s_keys_entry *entry;
	char buffer[d_string_buffer_size], *pointer;
	FILE *stream;
	if (!result)
		f_list_init(&result);
	if ((stream = fopen(file, "r"))) {
		while (!feof(stream)) {
			memset(buffer, 0, d_string_buffer_size);
			if (fgets(buffer, d_string_buffer_size, stream))
				if ((pointer = strchr(buffer, separator))) {
					*pointer = '\0';
					pointer++;
					f_string_trim(buffer);
					f_string_trim(pointer);
					if ((f_string_strlen(buffer) > 0) && (f_string_strlen(pointer) > 0))
						if ((entry = (struct s_keys_entry *) d_malloc(sizeof(struct s_keys_entry)))) {
							strncpy(entry->key, buffer, d_string_buffer_size);
							strncpy(entry->value, pointer, d_string_buffer_size);
							f_list_append(result, (struct s_list_node *)entry, e_list_insert_head);
						}
				}
		}
		fclose(stream);
	}
	return result;
}
开发者ID:nardinan,项目名称:magrathea,代码行数:28,代码来源:keys.c

示例13: CreateSphere

int CreateSphere (tSphereData *sdP)
{
	int			nFaces, i, j;
	tOOF_vector	*buf [2];

if (sdP->nFaceNodes == 3) {
	nFaces = 8;
	j = 6;
	}
else {
	nFaces = 6;
	j = 4;
	}
for (i = 0; i < sdP->nTessDepth; i++)
	nFaces *= j;
for (i = 0; i < 2; i++) {
	if (!(buf [i] = (tOOF_vector *) d_malloc (nFaces * (sdP->nFaceNodes + 1) * sizeof (tOOF_vector)))) {
		if (i)
			d_free (buf [i - 1]);
		return -1;
		}
	}
j = (sdP->nFaceNodes == 3) ? 
	 BuildSphereTri ((tOOF_triangle **) buf, &nFaces, sdP->nTessDepth) : 
	 BuildSphereQuad ((tOOF_quad **) buf, &nFaces, sdP->nTessDepth);
d_free (buf [!j]);
sdP->pSphere = buf [j];
return nFaces;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:29,代码来源:sphere.c

示例14: ui_create_dialog

UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, int (*callback)(UI_DIALOG *, d_event *, void *), void *userdata )
{
	UI_DIALOG	*dlg;
	int sw, sh, req_w, req_h;

	dlg = (UI_DIALOG *) d_malloc(sizeof(UI_DIALOG));
	if (dlg==NULL) Error("Could not create dialog: Out of memory");

	sw = grd_curscreen->sc_w;
	sh = grd_curscreen->sc_h;

	//mouse_set_limits(0, 0, sw - 1, sh - 1);

	req_w = w;
	req_h = h;

	dlg->flags = flags;

	if (flags & DF_BORDER)
	{
		x -= BORDER_WIDTH;
		y -= BORDER_WIDTH;
		w += 2*BORDER_WIDTH;
		h += 2*BORDER_WIDTH;
	}

	if ( x < 0 ) x = 0;
	if ( (x+w-1) >= sw ) x = sw - w;
	if ( y < 0 ) y = 0;
	if ( (y+h-1) >= sh ) y = sh - h;

	D_X = x;
	D_Y = y;
	D_WIDTH = w;
	D_HEIGHT = h;
	D_GADGET = NULL;
	dlg->keyboard_focus_gadget = NULL;
	selected_gadget = NULL;

	dlg->callback = callback;
	dlg->userdata = userdata;
	dlg->wind = window_create(&grd_curscreen->sc_canvas,
						 x + ((flags & DF_BORDER) ? BORDER_WIDTH : 0),
						 y + ((flags & DF_BORDER) ? BORDER_WIDTH : 0),
						 req_w, req_h, (int (*)(window *, d_event *, void *)) ui_dialog_handler, dlg);

	if (!dlg->wind)
	{
		d_free(dlg);
		return NULL;
	}

	if (!(flags & DF_MODAL))
		window_set_modal(dlg->wind, 0);	// make this window modeless, allowing events to propogate through the window stack

	return dlg;

}
开发者ID:Foran,项目名称:dxx-rebirth,代码行数:58,代码来源:dialog.cpp

示例15: d_define_method

d_define_method(emitter, record)(struct s_object *self, const char *id) {
	d_using(emitter);
	struct s_signal *signal;
	if ((signal = (struct s_signal *) d_malloc(sizeof(struct s_signal)))) {
		strncpy(signal->id, id, (d_emitter_name_size-1));
		f_list_append(emitter_attributes->signals, (struct s_list_node *)signal, e_list_insert_head);
	}
	return (void *)signal;
}
开发者ID:haifenghuang,项目名称:miranda,代码行数:9,代码来源:emitter.obj.c


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