//分配内存(外部调用)
//memx:所属内存块
//size:内存大小(字节)
//返回值:分配到的内存首地址.
void *cJsonMalloc(uint32_t size)  
{  
    uint32_t offset;  									      
	offset=memMalloc(size);  	   				   
    if(offset==0XFFFFFFFF)return NULL;  
    else return (void*)((uint32_t)mallco_dev.membase+offset);  
}  
//重新分配内存(外部调用)
//memx:所属内存块
//*ptr:旧内存首地址
//size:要分配的内存大小(字节)
//返回值:新分配到的内存首地址.
void *cJsonRealloc(void *ptr,uint32_t size)  
{  
    uint32_t offset;  
    offset=memMalloc(size);  
    if(offset==0XFFFFFFFF)return NULL;     
    else  
    {  									   
	    memCpy((void*)((uint32_t)mallco_dev.membase+offset),ptr,size);	//拷贝旧内存内容到新内存   
        cJsonFree(ptr);  											  		//释放旧内存
        return (void*)((uint32_t)mallco_dev.membase+offset);  				//返回新内存首地址
    }  
} 
Example #3
0
char *formatString(const char *format, ...)
{
	int len;
	char *ret;
	va_list args;
	va_start(args, format);
	len = vsnprintf(NULL, 0, format, args);
	va_end(args);
	ret = (char *)memMalloc(len + 1);
	va_start(args, format);
	vsprintf(ret, format, args);
	va_end(args);
	return ret;
}
Example #4
0
void Console::printf(const char *format, ...)
{
	char *output;
	va_list args;
	int lenOut;
	va_start(args, format);
	lenOut = vsnprintf(NULL, 0, format, args) + 1;
	va_end(args);
	output = (char *)memMalloc(lenOut);
	va_start(args, format);
	vsprintf(output, format, args);
	va_end(args);
	Print(std::string(output));
	free(output);
}
Example #5
0
TMH_DKR* createTMHDKRInstance( TMHGraph* const graphData, TMHConfig* const configuration ) {
	TMH_DKR* newInstance = memMalloc(1,sizeof(TMH_DKR));
	newInstance->graphData = graphData;
	newInstance->configuration = configuration;

	if ( configuration->allowInterrupt ) {
		printf("%s\n",ASK_FOR_WIDTH_OF_HEAP);
		newInstance->dHeapParameter = getParameterOrDefaultDKR(graphData->numberOfArcs,graphData->numberOfNodes);
	} else if ( configuration->defaultParameter == NULL ) {
		newInstance->dHeapParameter = findBestParameter(graphData->numberOfArcs,graphData->numberOfNodes);
	} else {
		newInstance->dHeapParameter = *(configuration->defaultParameter);
	}
	if (isInfoLogEnabled()) {
		info(MODULE_NAME,info_DKR_parametrReaded,newInstance->dHeapParameter);
	}

	return newInstance;
}
Example #6
0
/*static*/ DATA_BIN_PTR db_make(char *title)
{
	DATA_BIN_PTR dbin;

	dbin = (DATA_BIN_PTR)memMalloc(sizeof(DATA_BIN), "dbin");

	if (dbin == NULL)
	{
		err_push(ERR_MEM_LACK, "Data Bin");
		return(NULL);
	}

	/* Initialize data_bin */

#ifdef FF_CHK_ADDR
	dbin->check_address = (void*)dbin;
#endif

	if (title)
	{
		dbin->title = (char *)memStrdup(title, "dbin->title"); /* (char *) for Think C -rf01 */
		if (dbin->title == NULL)
		{
			err_push(ERR_MEM_LACK, "Data Bin Title");
			memFree(dbin, "dbin");
			return(NULL);
		}
	}
	else
		dbin->title = NULL;

	dbin->table_list = NULL;
	
	dbin->array_conduit_list = NULL;

	dbin->eqn_info = NULL;

	return(dbin);
}
Example #7
0
TMHNodeSlim* createTMHNodeSlimInstance( const TMHNode* const node ) {
	TMHNodeSlim* newNode = memMalloc(1,sizeof(TMHNodeSlim));
	newNode->nodeID = node->nodeID;
	newNode->distanceLabel = node->distanceLabel;
	return newNode;
}
Example #8
0
static DLL_NODE_PTR dll_node_create(void)
#endif
/*****************************************************************************
 * NAME: dll_node_create()
 *
 * PURPOSE:  Allocate a memory block for a new DLL_NODE, plus dsize for data
 *
 * USAGE:  node = dll_node_create();
 *
 * RETURNS:  NULL if operation fails, otherwise a pointer to an allocated
 * node/data block
 *
 * DESCRIPTION:  Allocates space for DLL_NODE.
 *
 * AUTHOR:  Mark Ohrenschall, NGDC, (303) 497-6124, [email protected]
 *
 * SYSTEM DEPENDENT FUNCTIONS:
 *
 * GLOBALS:
 *
 * COMMENTS:
 *
 * KEYWORDS:
 *
 * ERRORS:
 ****************************************************************************/
{
	DLL_NODE_PTR node;

	/* Get memory for data element and set dll_data(node)
	to point to it */

	node = (DLL_NODE_PTR)memMalloc(sizeof(DLL_NODE), "List Node");

	if (node == NULL)
	{
		err_push(ERR_MEM_LACK, "Allocating list node");
		return(NULL);
	}

#ifdef FF_CHK_ADDR
	node->check_address = node;
#endif

#ifdef DLL_CHK
	DLL_SET_NEW(node);
#endif
	
	node->next = node->previous = NULL;
#ifdef DLL_CHK
	node->count = node->data.type = 0;
#endif
	node->data.u.var = NULL;
	
	/* Find header */
#ifdef DLL_CHK
	if (link_node)
		DLL_COUNT(find_head_node(link_node))++;
#endif

	return(node);
}