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


C++ MALLOC_CHECK函数代码示例

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


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

示例1: MALLOC_CHECK

void *xrealloc (void *ptr, size_t bytes)
#endif
{
    void *cp;

	MALLOC_CHECK();
#ifdef _DEBUG
    if (!ptr)
		cp = _malloc_dbg(bytes?bytes:1,_NORMAL_BLOCK,file,line);
	else
		cp = _realloc_dbg(ptr, bytes,_NORMAL_BLOCK,file,line);
#else
    if (!ptr)
		cp = malloc (bytes?bytes:1);
	else
		cp = realloc(ptr, bytes);
#endif

    if (cp == NULL)
    {
		char buf[80];
		sprintf (buf, "out of memory; can not reallocate %lu bytes",
			(unsigned long) bytes);
		error (1, 0, buf);
    }
	MALLOC_CHECK();
    return (cp);
}
开发者ID:pampersrocker,项目名称:G-CVSNT,代码行数:28,代码来源:subr.cpp

示例2: malloc

list_node *add_list_node(list_node *head, void *pdata, size_t len)
{
    list_node *last_node, *new_node;

    /* create new head */
    if (head->data == NULL)
    {
        head->data = malloc(len);
        MALLOC_CHECK(head->data);
        memcpy(head->data, pdata, len);

        new_node = head;
    }
    else
    {
        last_node = head;
        while (last_node->next)
            last_node = last_node->next;

        new_node = (list_node *) calloc(1, sizeof(list_node));
        MALLOC_CHECK(new_node);
        new_node->data = malloc(len);
        MALLOC_CHECK(new_node->data);
        memcpy(new_node->data, pdata, len);

        /* link in new node */
        last_node->next = new_node;
    }
    
    return new_node;
}
开发者ID:snsl,项目名称:pvfs2-osd,代码行数:31,代码来源:client-test.c

示例3: DAdd

//tries to add an entry into the dictionary
void DAdd(void* data, char* key){
   
   int num = hash(key);
   if (dict->start == NULL){//first element; dictionary empty
      MYASSERT(dict->end == NULL);
      dict->start = dict->end = (DNODE *)NEW(DNODE);
      MALLOC_CHECK(dict->start);
      dict->start->prev = dict->start->next = NULL;
      dict->hash[num] = dict->start;
      dict->start->data = data;
      BZERO(dict->start->key, KEY_LENGTH);
      strncpy(dict->start->key, key, KEY_LENGTH);
   }

   else{
      DNODE *d;
 
      if (dict->hash[num] == NULL){//non-collision case
	 d = NEW(DNODE);
	 dict->hash[num] = d;
	 d->next = NULL;
	 d->prev = dict->end;
	 dict->end->next = d;
	 dict->end = d;
	 BZERO(d->key, KEY_LENGTH);
	 strncpy(d->key, key, KEY_LENGTH);
	 d->data = data;
      }
      else {//collision case
	 int unique = TRUE;
	 DNODE *temp = dict->hash[num];
	 //as long as the hashes are the same, keep going
	 while (hash(temp->key) == num){
	    //check for matches
	    if (strncmp(temp->key, key, MAX_URL_LENGTH) == 0)
	       unique = FALSE;
	    if (temp->next == NULL || unique == FALSE)
	       break;//reached the end or we know it's not unique
	    temp = temp->next;
	 }
	 //only add if we didn't find the url in the list
	 if (unique == TRUE){
	    temp = temp->prev;
	    DNODE *d = NEW(DNODE);
	    MALLOC_CHECK(d);
	    d->next = temp->next;
	    d->prev = temp;
	    if (d->next == NULL)//for the case that hash[num] is at the end
	       dict->end = d;
	    else
	       temp->next->prev = d;
	    temp->next = d;
	    BZERO(d->key, KEY_LENGTH);
	    strncpy(d->key, key, KEY_LENGTH);
	    d->data = data;
	 }
      }
   }
}
开发者ID:patxu,项目名称:cs50-Software-Design-and-Implementation,代码行数:60,代码来源:dictionary.c

示例4: insertElementIntoIndex

// tweaked version of update index to insert an element into the index along with with the frequency
int insertElementIntoIndex(char* word, int documentId, int frequency, INVERTED_INDEX* index) {
	int hashIndex = hash1(word)%MAX_HASH_SLOT;
	// something is in there already
	if ((index->hash[hashIndex]) != NULL) {
		DocumentNode* init;
		init = (index->hash[hashIndex])->page;
		
		if(init->document_id == documentId) {
			init->page_word_frequency = frequency;
			(index->hash[hashIndex])->page = init;
		}
		else {
			DocumentNode* d;
			
			if(index->hash[hashIndex]) {
				int flag = 0;
				
				d = (index->hash[hashIndex])->page;
				while ((d->next) != NULL) {
					d = d->next;
					if(d->document_id == documentId) {
						//we found the same documentId
						d->page_word_frequency = frequency;
						flag = 1;
						break;
					}
				}
				
				if (flag == 0) {
					// documentId not present
					DocumentNode* dd = (DocumentNode*)malloc(sizeof(DocumentNode));
					MALLOC_CHECK(dd);
					dd->next = NULL;
					dd->document_id = documentId;
					dd->page_word_frequency = frequency;
					
					if (d->next == NULL) {
						d->next = dd;
					}
				}
			}
		}
		
		return 1;
	}
	// nothing is in there already
	else {		
		DocumentNode* doc = malloc(sizeof(DocumentNode));
		MALLOC_CHECK(doc);
		doc->document_id = documentId;
		doc->page_word_frequency = frequency;
		doc->next = NULL;
		
		// add element into the index
		IndexAdd(index, (void*)doc, word);
		return 1;	
	}
}
开发者ID:codelurker,项目名称:TinySearch-Engine,代码行数:59,代码来源:dictionary.c

示例5: digsyl

char *
digsyl(int range, int width)
{
	int i,
		base = 1,
		target;
	static char *new_dig = NULL;
	static int last_width = 0;

	if (range <= 0 || width < 0)
		return(NULL);
	
	if (width == 0) 
		{
		base=1;width=1;
		while(base <= range/10)
			{
			width++;
			base *= 10 ;
			}
		} 
	else  
		{
		for (i=0; i < width - 1; i++)
			base *= 10;
		}
	
	if (new_dig == NULL)
		{
		new_dig = (char *)malloc(sizeof(char) * SYL_WIDTH * width + 1);
		MALLOC_CHECK(new_dig);
		last_width = width;
		}
	else
		{
		new_dig[0] = '\0';
		if (last_width < width)
			{
			new_dig = 
				(char *)realloc(new_dig, width * sizeof(char) * SYL_WIDTH + 1);
			MALLOC_CHECK(new_dig);
			last_width = width;
			}
		}

	for (i=0; i < width * SYL_WIDTH; i += SYL_WIDTH)
		{
		target = range - (range % base);
		target /= base;
		strcpy(new_dig + i, digsyllables[target % 10]);
		range -= base * target;
		base /= 10;
		}

	return(new_dig);
}
开发者ID:onlyindreams,项目名称:dbt1,代码行数:56,代码来源:tpcw.c

示例6: MALLOC_CHECK

// TODO: move to util
interp_workspace *new_interp_workspace(int upsample_ratio, interp_stats *stats) {
  interp_workspace *w = (interp_workspace *)malloc(sizeof(interp_workspace));
  MALLOC_CHECK(w);
  w->input = gsl_vector_alloc(NUM_STENCIL_POINTS);
  MALLOC_CHECK(w->input);
  w->output = gsl_vector_alloc((upsample_ratio+1)*(upsample_ratio+1));
  MALLOC_CHECK(w->output);
  w->stats = stats;
  return w;
}
开发者ID:foxydude,项目名称:qc,代码行数:11,代码来源:count_nodal_domains.c

示例7: xfree_s

/* Automatically null the pointer after freeing it */
void xfree_s(void **ptr)
{
	MALLOC_CHECK();
	if(*ptr)
	{
		free(*ptr);
		MALLOC_CHECK();
	}
	*ptr=NULL;
}
开发者ID:pampersrocker,项目名称:G-CVSNT,代码行数:11,代码来源:subr.cpp

示例8: ProcessNames

/*
 * Routine: ProcessNames
 * Purpose: Parse the name vector
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By:
 * Calls:
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
int
ProcessNames (char *stmt, token_t * tokens)
{
    char *szResult = NULL;
    char *cp;
    int nCount = 0,
        nWordLength = 0;

    /* get the names */
    while ((cp = strtok (NULL, "=( ,);:")) != NULL)
    {
        if (nCount == 0)
        {
            nWordLength = strlen(cp);
            szResult = malloc(nWordLength + 1);
            MALLOC_CHECK(szResult);
            nCount = nWordLength + 1;
            strcpy(szResult, cp);
        }
        else
        {
            nWordLength = strlen(cp);
            szResult = realloc(szResult, nCount + nWordLength + 1);
            strcpy(szResult + nCount, cp);
            nCount += nWordLength + 1;

        }
    }

    pCurrentIndexEntry->dist->names = szResult;
    return (nCount);
}
开发者ID:fengttt,项目名称:TPC-DS,代码行数:46,代码来源:dcgram.c

示例9: WriteFile

// Function to write the webpage to a file.
int WriteFile(WebPage *wp, char *path, int pageID) {
	// Declare and initialize a filename variable.
	char *filename = (char *)malloc(20);
    	MALLOC_CHECK(stderr,filename);
    
    	// Write to the filename variable.
	if (sprintf(filename, "%s/%d", path, pageID) == EOF) {
    		printf("There is an error with the directory path.\n");
    		return 0;
    	}
    
    	// Declare and open a filepath with the filename.
    	FILE *fp;
    	fp = fopen(filename, "w+"); // Open a new file by the filename.
	
	// Check that there were no errors opening the file.
   	if (fp == NULL) {
    		printf("Error reading file.\n");
    		return 0;
    	}
    
    	// Write to each file of an html.
    	fprintf(fp, "%s\n%d\n%s", wp->url, wp->depth, wp->html);
    
    	// Cleanup.
	fclose(fp);
	free(filename);
	return 1;
}
开发者ID:cjunmokim,项目名称:Search-Engine,代码行数:30,代码来源:crawler.c

示例10: processSearchTerms

//takes in an array of search terms, gets the docID, score, and which list it should be added in
//and passes the information to the function addScoreToList to be added to the list
//
//PSEUDO CODE
//for all searchterms
//    get the docIDs associated with the word and add the score to the list but factor in a WEIGHT
//    if the prev searchterm is not OR
//	 add to list with weight
//    else
//	 add to the list
void processSearchTerms(INVERTED_INDEX* index, char* searchterms) {
    int docID;
    int score;
    char* prevterm = NULL;
    char* currentterm;
    int pos;
    DOCNODE* d;
    while (searchterms != NULL) {
        currentterm = searchterms;
        pos = 0;
        if(isSearchTerm(currentterm) == TRUE) { //if it's a search term, normalize it and search for it
            NormalizeWord(currentterm);
            while((d = getDoc(index, currentterm, &pos)) != NULL) {
                docID = d->doc_id;
                score = d->page_word_freq;
                if(isNotOR(prevterm) == TRUE) { //add with weighteded score because it must be ADD
                    addScoreToList(querylist, TRUE, docID, (score*WEIGHT));
                }
                else//add with regular score
                    addScoreToList(querylist, FALSE, docID, score);
            }
        }
        prevterm = currentterm;
        searchterms = strtok(NULL, " "); //get next searchterm
    }
    if (querylist->start != NULL) {
        slist = NEW(SORTLIST);
        MALLOC_CHECK(slist);
        BZERO(slist, sizeof(SORTLIST));
        sortList(slist, querylist);
        printList(slist);
    }
}
开发者ID:patxu,项目名称:cs50-Software-Design-and-Implementation,代码行数:43,代码来源:sortlist.c

示例11: set_files

/*
* re-set default output file names 
*/
int
set_files (int i, int pload)
{
	char line[80], *new_name;
	
	if (table & (1 << i))
child_table:
	{
		if (pload != -1)
			sprintf (line, "%s.%d", tdefs[i].name, pload);
		else
		{
			printf ("Enter new destination for %s data: ",
				tdefs[i].name);
			if (fgets (line, sizeof (line), stdin) == NULL)
				return (-1);;
			if ((new_name = strchr (line, '\n')) != NULL)
				*new_name = '\0';
			if (strlen (line) == 0)
				return (0);
		}
		new_name = (char *) malloc (strlen (line) + 1);
		MALLOC_CHECK (new_name);
		strcpy (new_name, line);
		tdefs[i].name = new_name;
		if (tdefs[i].child != NONE)
		{
			i = tdefs[i].child;
			tdefs[i].child = NONE;
			goto child_table;
		}
	}
	
	return (0);
}
开发者ID:YIwama,项目名称:bcb,代码行数:38,代码来源:driver.c

示例12: permute_dist

long *
permute_dist(distribution *d, long stream)
	{
	static distribution *dist = NULL;
	int i;
	
	if (d != NULL)
		{
		if (d->permute == (long *)NULL)
			{
			d->permute = (long *)malloc(sizeof(long) * (DIST_SIZE(d)));
			MALLOC_CHECK(d->permute);
			for (i=0; i < (DIST_SIZE(d)); i++) 
				*(d->permute + i) = i;
			}
		dist = d;
		return(permute(dist->permute, DIST_SIZE(dist), stream));
		}
	
	
	if (dist != NULL)
		return(permute(NULL, DIST_SIZE(dist), stream));
	else
		INTERNAL_ERROR("Bad call to permute_dist");	
	}
开发者ID:YIwama,项目名称:bcb,代码行数:25,代码来源:permute.c

示例13: makePermutation

/*
* Routine: MakePermutation(int nSize)
* Purpose: Permute the integers in [1..nSize]
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int *
makePermutation(int *nNumberSet, int nSize, int nStream)
{
	int i,
		nTemp,
		nIndex,
		*pInt;

	if (nSize <= 0)
		return(NULL);

	if (!nNumberSet)
	{
		nNumberSet = (int *)malloc(nSize * sizeof(int));
		MALLOC_CHECK(nNumberSet);
		pInt = nNumberSet;
		for (i=0; i < nSize; i++)
			*pInt++ = i;
	}

	for (i=0; i < nSize; i++)
	{
		nIndex = genrand_integer(NULL, DIST_UNIFORM, 0, nSize - 1, 0, nStream);
		nTemp = nNumberSet[i];
		nNumberSet[i] = nNumberSet[nIndex];
		nNumberSet[nIndex] = nTemp;
	}

	return(nNumberSet);
}
开发者ID:Pivotal-Field-Engineering,项目名称:tpcds-dev,代码行数:44,代码来源:permute.c

示例14: initQueryList

//initializes the querylist
void initQueryList() {
    querylist = NEW(QUERYLIST);
    MALLOC_CHECK(querylist);
    BZERO(querylist, sizeof(QUERYLIST));
    querylist->start = querylist->end = NULL;
    for (int i = 0; i < MAX_HASH_SLOT; i++)
        querylist->hash[i] = NULL;
}
开发者ID:patxu,项目名称:cs50-Software-Design-and-Implementation,代码行数:9,代码来源:sortlist.c

示例15: getopt

int
getopt(int ac, char **av, char *opt)
{
    static char *nextchar = NULL;
    char *cp;
    char hold;

    if (optarg == NULL)
        {
        optarg = (char *)malloc(BUFSIZ);
        MALLOC_CHECK(optarg);
        }

    if (!nextchar || *nextchar == '\0')
        {
        optind++;
        if (optind == ac)
            return(-1);
        nextchar = av[optind];
        if (*nextchar != '-')
            return(-1);
        nextchar +=1;
        }

    if (nextchar && *nextchar == '-')   /* -- termination */
        {
        optind++;
        return(-1);
        }
    else        /* found an option */
        {
        cp = strchr(opt, *nextchar);
        nextchar += 1;
        if (cp == NULL) /* not defined for this run */
            return('?');
        if (*(cp + 1) == ':')   /* option takes an argument */
            {
            if (*nextchar)
                {
                hold = *cp;
                cp = optarg;
                while (*nextchar)
                    *cp++ = *nextchar++;
                *cp = '\0';
                *cp = hold;
                }
            else        /* white space separated, use next arg */
                {
                if (++optind == ac)
                    return('?');
                strcpy(optarg, av[optind]);
                }
            nextchar = NULL;
            }
        return(*cp);
        }
}
开发者ID:chsc0817,项目名称:DBImpl-projekt,代码行数:57,代码来源:bm_utils.c


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