您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ vApplicationMallocFailedHook函数代码示例

51自学网 2021-06-03 09:30:32
  C++
这篇教程C++ vApplicationMallocFailedHook函数代码示例写得很实用,希望能帮到您。

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

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

示例1: vTaskSuspendAll

void *pvPortMalloc(size_t xWantedSize) {    void *pvReturn = NULL;    /* Ensure that blocks are always aligned to the required number of bytes. */#if portBYTE_ALIGNMENT != 1    if (xWantedSize & portBYTE_ALIGNMENT_MASK) {        /* Byte alignment required. */        xWantedSize += (portBYTE_ALIGNMENT - (xWantedSize & portBYTE_ALIGNMENT_MASK));    }#endif    vTaskSuspendAll();    {        /* Check there is enough room left for the allocation. */        if (((xNextFreeByte + xWantedSize) < configTOTAL_HEAP_SIZE) &&                ((xNextFreeByte + xWantedSize) > xNextFreeByte)) { /* Check for overflow. */            /* Return the next free byte then increment the index past this            block. */            pvReturn = &(xHeap.ucHeap[ xNextFreeByte ]);            xNextFreeByte += xWantedSize;        }    }    xTaskResumeAll();#if( configUSE_MALLOC_FAILED_HOOK == 1 )    {        if (pvReturn == NULL) {            extern void vApplicationMallocFailedHook(void);            vApplicationMallocFailedHook();        }    }#endif    return pvReturn;}
开发者ID:emkaychen,项目名称:bachelorthesis,代码行数:35,


示例2: vTaskSuspendAll

void *osAllocMem2(unsigned int size){   void *pvReturn;   //Suspends all the tasks while keeping interrupts enabled   vTaskSuspendAll();   //Allocate memory block   pvReturn = malloc(size);   //Resume all the tasks   xTaskResumeAll();   //Debug message   //TRACE_DEBUG("Allocate %d bytes at 0x%08X/r/n", xSize, pvReturn);   if(pvReturn == NULL)   {      pvReturn = NULL;////      TRACE_ERROR("#######################Out of mem!######################/r/n");   }#if configUSE_MALLOC_FAILED_HOOK == 1   //Memory allocation failed?	if(pvReturn == NULL)	{	   extern void vApplicationMallocFailedHook(void);	   vApplicationMallocFailedHook();	}#endif      //Return a pointer to the memory block   return pvReturn;}
开发者ID:Velleman,项目名称:VM204-Firmware,代码行数:30,


示例3: vRAMFSMalloc

size_t vRAMFSMalloc( size_t xWantedSize ){size_t vReturn = 0;	/* Check there is enough room left for the allocation. */	if( ( ( xNextFreeRAMFSByte + xWantedSize ) < configTOTAL_RAMFS_SIZE ) &&		( ( xNextFreeRAMFSByte + xWantedSize ) > xNextFreeRAMFSByte )	)/* Check for overflow. */	{		/* Return the next free byte then increment the index past this		block. */		vReturn = (size_t) XRAMSTART + xNextFreeRAMFSByte;		xNextFreeRAMFSByte += xWantedSize;	}	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif	return vReturn;}
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:avrfreertos,代码行数:27,


示例4: vTaskSuspendAll

void *pvPortMalloc( size_t xWantedSize ){void *pvReturn = NULL;static uint8_t *pucAlignedHeap = NULL;	/* Ensure that blocks are always aligned to the required number of bytes. */	#if( portBYTE_ALIGNMENT != 1 )	{		if( xWantedSize & portBYTE_ALIGNMENT_MASK )		{			/* Byte alignment required. */			xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );		}	}	#endif	vTaskSuspendAll();	{		if( pucAlignedHeap == NULL )		{			/* Ensure the heap starts on a correctly aligned boundary. */			pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );		}		/* Check there is enough room left for the allocation. */		if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) &&			( ( xNextFreeByte + xWantedSize ) > xNextFreeByte )	)/* Check for overflow. */		{			/* Return the next free byte then increment the index past this			block. */			pvReturn = pucAlignedHeap + xNextFreeByte;			xNextFreeByte += xWantedSize;		}		traceMALLOC( pvReturn, xWantedSize );	}	( void ) xTaskResumeAll();	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif	return pvReturn;}
开发者ID:Eclo,项目名称:FreeRTOS,代码行数:50,


示例5: pvPortMalloc

void *pvPortMalloc(size_t s){	void *p;	vPortEnterCritical();	p = msheap_alloc(s);	vPortExitCritical();	if (p == NULL && &vApplicationMallocFailedHook != NULL)		vApplicationMallocFailedHook();	return p;}
开发者ID:PhilippePetit,项目名称:openpilot,代码行数:14,


示例6: freertos_print

void *pvPortMalloc( size_t xWantedSize ){void *pvReturn = NULL; freertos_print("Called pvPortMalloc in heap_1./n");	/* Ensure that blocks are always aligned to the required number of bytes. */	#if portBYTE_ALIGNMENT != 1		if( xWantedSize & portBYTE_ALIGNMENT_MASK )		{			/* Byte alignment required. */			xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );		}	#endif		//		freertos_print("Suspending in pvPortMalloc()/n");	vTaskSuspendAll();	{		/* Check there is enough room left for the allocation. */		if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) &&			( ( xNextFreeByte + xWantedSize ) > xNextFreeByte )	)/* Check for overflow. */		{			/* Return the next free byte then increment the index past this			block. */			pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] );			xNextFreeByte += xWantedSize;		} else {			freertos_print("Not enough memory to allocate requested size, %u, only have %u/n", xWantedSize, configTOTAL_HEAP_SIZE - xNextFreeByte);			freertos_print("Heap size: %u/n", configTOTAL_HEAP_SIZE);			freertos_print("Current bump pointer %u/n", xNextFreeByte);		}	}	//	freertos_print("Resuming in pvPortMalloc()/n");	xTaskResumeAll();	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif		//	freertos_print("Returning from pvPortMalloc()/n");	return pvReturn;}
开发者ID:EmuxEvans,项目名称:CompositeFreeRTOS,代码行数:46,


示例7: malloc

void *pvPortMalloc( size_t xWantedSize ){void *pvReturn;	{		pvReturn = malloc( xWantedSize );	}	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif		return pvReturn;}
开发者ID:1heinz,项目名称:TauLabs,代码行数:20,


示例8: vTaskSuspendAll

static void *_pvPortCalloc( size_t xWantedNum, size_t xWantedSize  ){void *pvReturn;	vTaskSuspendAll();	{		pvReturn = calloc( xWantedNum, xWantedSize );	}	xTaskResumeAll();	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif		return pvReturn;}
开发者ID:Duiesel,项目名称:thebirdfree-personal,代码行数:22,


示例9: vTaskSuspendAll

void *pvPortMalloc( size_t xWantedSize ){	void *pvReturn;	//	freertos_print("WRONG MALLOC, IDIOT/n");	vTaskSuspendAll();	{		pvReturn = malloc( xWantedSize );	}	xTaskResumeAll();	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			freertos_print("Malloc failed from heap_3/n");			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif		return pvReturn;}
开发者ID:EmuxEvans,项目名称:CompositeFreeRTOS,代码行数:23,


示例10: vTaskSuspendAll

void *pvPortMalloc( size_t xWantedSize ){BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;static BaseType_t xHeapHasBeenInitialised = pdFALSE;void *pvReturn = NULL;	vTaskSuspendAll();	{		/* If this is the first call to malloc then the heap will require		initialisation to setup the list of free blocks. */		if( xHeapHasBeenInitialised == pdFALSE )		{			prvHeapInit();			xHeapHasBeenInitialised = pdTRUE;		}		/* The wanted size is increased so it can contain a BlockLink_t		structure in addition to the requested amount of bytes. */		if( xWantedSize > 0 )		{			xWantedSize += heapSTRUCT_SIZE;			/* Ensure that blocks are always aligned to the required number of bytes. */			if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0 )			{				/* Byte alignment required. */				xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );			}		}		if( ( xWantedSize > 0 ) && ( xWantedSize < configADJUSTED_HEAP_SIZE ) )		{			/* Blocks are stored in byte order - traverse the list from the start			(smallest) block until one of adequate size is found. */			pxPreviousBlock = &xStart;			pxBlock = xStart.pxNextFreeBlock;			while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )			{				pxPreviousBlock = pxBlock;				pxBlock = pxBlock->pxNextFreeBlock;			}			/* If we found the end marker then a block of adequate size was not found. */			if( pxBlock != &xEnd )			{				/* Return the memory space - jumping over the BlockLink_t structure				at its start. */				pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );				/* This block is being returned for use so must be taken out of the				list of free blocks. */				pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;				/* If the block is larger than required it can be split into two. */				if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )				{					/* This block is to be split into two.  Create a new block					following the number of bytes requested. The void cast is					used to prevent byte alignment warnings from the compiler. */					pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );					/* Calculate the sizes of two blocks split from the single					block. */					pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;					pxBlock->xBlockSize = xWantedSize;					/* Insert the new block into the list of free blocks. */					prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );				}				xFreeBytesRemaining -= pxBlock->xBlockSize;			}		}		traceMALLOC( pvReturn, xWantedSize );	}	( void ) xTaskResumeAll();	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif	return pvReturn;}
开发者ID:AaronCohen1,项目名称:temp-497.31,代码行数:90,


示例11: vTaskSuspendAll

//.........这里部分代码省略.........            if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )            {                /* Traverse the list from the start	(lowest address) block until                one	of adequate size is found. */                pxPreviousBlock = &xStart;                pxBlock = xStart.pxNextFreeBlock;                while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )                {                    pxPreviousBlock = pxBlock;                    pxBlock = pxBlock->pxNextFreeBlock;                }                /* If the end marker was reached then a block of adequate size                was	not found. */                if( pxBlock != pxEnd )                {                    /* Return the memory space pointed to - jumping over the                    BlockLink_t structure at its start. */                    pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );                    /* This block is being returned for use so must be taken out                    of the list of free blocks. */                    pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;                    /* If the block is larger than required it can be split into                    two. */                    if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )                    {                        /* This block is to be split into two.  Create a new                        block following the number of bytes requested. The void                        cast is used to prevent byte alignment warnings from the                        compiler. */                        pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );                        configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );                        /* Calculate the sizes of two blocks split from the                        single block. */                        pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;                        pxBlock->xBlockSize = xWantedSize;                        /* Insert the new block into the list of free blocks. */                        prvInsertBlockIntoFreeList( pxNewBlockLink );                    }                    else                    {                        mtCOVERAGE_TEST_MARKER();                    }                    xFreeBytesRemaining -= pxBlock->xBlockSize;                    if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )                    {                        xMinimumEverFreeBytesRemaining = xFreeBytesRemaining;                    }                    else                    {                        mtCOVERAGE_TEST_MARKER();                    }                    /* The block is being returned - it is allocated and owned                    by the application and has no "next" block. */                    pxBlock->xBlockSize |= xBlockAllocatedBit;                    pxBlock->pxNextFreeBlock = NULL;                }                else                {                    mtCOVERAGE_TEST_MARKER();                }            }            else            {                mtCOVERAGE_TEST_MARKER();            }        }        else        {            mtCOVERAGE_TEST_MARKER();        }        traceMALLOC( pvReturn, xWantedSize );    }    ( void ) xTaskResumeAll();#if( configUSE_MALLOC_FAILED_HOOK == 1 )    {        if( pvReturn == NULL )        {            extern void vApplicationMallocFailedHook( void );            vApplicationMallocFailedHook();        }        else        {            mtCOVERAGE_TEST_MARKER();        }    }#endif    configASSERT( ( ( ( size_t ) pvReturn ) & ( size_t ) portBYTE_ALIGNMENT_MASK ) == 0 );    return pvReturn;}
开发者ID:RidleyWalker,项目名称:micropython,代码行数:101,


示例12: pre_alloc_hook

//.........这里部分代码省略.........			while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock ) )			{				pxPreviousBlock = pxBlock;				pxBlock = pxBlock->pxNextFreeBlock;			}			/* If we found the end marker then a block of adequate size was not found. */			if( pxBlock != &xEnd )			{				/* Return the memory space - jumping over the xBlockLink structure				at its start. */				pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock )							+ heapSTRUCT_SIZE );#ifdef FREERTOS_ENABLE_MALLOC_STATS				hI.totalAllocations++;#endif // FREERTOS_ENABLE_MALLOC_STATS				/* This block is being returned for use so must be taken off the				list of free blocks. */				pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;				pxBlock->pxNextFreeBlock = NULL;				/* If the block is larger than required it can be split into two. */				if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )				{					/* This block is to be split into two.  Create a new block					following the number of bytes requested. The void cast is					used to prevent byte alignment warnings from the compiler. */					pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );					/* Calculate the sizes of two blocks split from the single					block. */					pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;					/* Assume bit 0 is 0 i.e. BLOCK_ALLOCATED flag is clear */					pxBlock->xBlockSize = xWantedSize; 					/* Add the new block to the serial list */					pxNewBlockLink->pxPrev = pxBlock;					if( ! IS_LAST_BLOCK(pxNewBlockLink) )						NEXT_BLOCK( pxNewBlockLink )->pxPrev = 							pxNewBlockLink;					SET_ALLOCATED(pxBlock);					/* insert the new block into the list of free blocks. */					prvInsertBlockIntoFreeList( pxNewBlockLink );				}				else {					SET_ALLOCATED(pxBlock);				}				xFreeBytesRemaining -= BLOCK_SIZE(pxBlock);			}		}	}	xTaskResumeAll();#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			DTRACE("Heap allocation failed./n/r"				       "Requested: %d/n/r"				       "Available : %d/n/r", xWantedSize, xFreeBytesRemaining);			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}#else	if( pvReturn == NULL ) {		DTRACE("Heap allocation failed./n/r"		      "Requested: %d/n/r"		      "Available : %d/n/r", xWantedSize, xFreeBytesRemaining);#ifdef FREERTOS_ENABLE_MALLOC_STATS		hI.failedAllocations++;#endif /* FREERTOS_ENABLE_MALLOC_STATS */	}#endif	if(pvReturn) {		SET_ACTUAL_SIZE( pxBlock );		SET_CALLER_ADDR( pxBlock );		ATRACE("MDC A %10x %6d %10d R: %x/r/n", pvReturn ,		       BLOCK_SIZE( pxBlock ),		       xFreeBytesRemaining, __builtin_return_address(0));		randomizeAreaData((unsigned char*)pvReturn, 				  BLOCK_SIZE( pxBlock ) - heapSTRUCT_SIZE);		post_alloc_hook( pvReturn );#ifdef FREERTOS_ENABLE_MALLOC_STATS		if ((configTOTAL_HEAP_SIZE - xFreeBytesRemaining) > hI.peakHeapUsage) {			hI.peakHeapUsage =				(configTOTAL_HEAP_SIZE - xFreeBytesRemaining);		}#endif	}		return pvReturn;}
开发者ID:Jansonhuang,项目名称:aws_starter_sdk,代码行数:101,


示例13: vPortDefineHeapRegions

//.........这里部分代码省略.........					pxPreviousBlock = pxBlock;					pxBlock = pxBlock->pxNextFreeBlock;				}				/* If the end marker was reached then a block of adequate size				was	not found. */				if( pxBlock != pxEnd )				{					/* Return the memory space pointed to - jumping over the					BlockLink_t structure at its start. */					pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + uxHeapStructSize );					/* This block is being returned for use so must be taken out					of the list of free blocks. */					pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;					/* If the block is larger than required it can be split into					two. */					if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )					{						/* This block is to be split into two.  Create a new						block following the number of bytes requested. The void						cast is used to prevent byte alignment warnings from the						compiler. */						pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );						/* Calculate the sizes of two blocks split from the						single block. */						pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;						pxBlock->xBlockSize = xWantedSize;						/* Insert the new block into the list of free blocks. */						prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );					}					else					{						mtCOVERAGE_TEST_MARKER();					}					xFreeBytesRemaining -= pxBlock->xBlockSize;					if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )					{						xMinimumEverFreeBytesRemaining = xFreeBytesRemaining;					}					else					{						mtCOVERAGE_TEST_MARKER();					}					/* The block is being returned - it is allocated and owned					by the application and has no "next" block. */					pxBlock->xBlockSize |= xBlockAllocatedBit;					pxBlock->pxNextFreeBlock = NULL;                    #ifdef MEMLEAK_DEBUG					if(uxHeapStructSize >= sizeof( BlockLink_t )){						pxBlock->file = file;						pxBlock->line = line;					}					//link the use block					prvInsertBlockIntoUsedList(pxBlock);#endif				}				else				{					mtCOVERAGE_TEST_MARKER();				}			}			else			{				mtCOVERAGE_TEST_MARKER();			}		}		else		{			mtCOVERAGE_TEST_MARKER();		}		traceMALLOC( pvReturn, xWantedSize );	}	// ( void ) xTaskResumeAll();    ETS_INTR_UNLOCK();	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}		else		{			mtCOVERAGE_TEST_MARKER();		}	}	#endif	return pvReturn;}
开发者ID:karawin,项目名称:Ka-Radio,代码行数:101,


示例14: ETS_INTR_LOCK

void *pvPortMalloc( size_t xWantedSize ){    xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink;    void *pvReturn = NULL;//    printf("%s %d %d/n", __func__, xWantedSize, xFreeBytesRemaining);//	vTaskSuspendAll();    ETS_INTR_LOCK();    {        /* If this is the first call to malloc then the heap will require        initialisation to setup the list of free blocks. */        if( pxEnd == NULL )        {            prvHeapInit();        }        /* Check the requested block size is not so large that the top bit is        set.  The top bit of the block size member of the xBlockLink structure        is used to determine who owns the block - the application or the        kernel, so it must be free. */        if( ( xWantedSize & xBlockAllocatedBit ) == 0 )        {            /* The wanted size is increased so it can contain a xBlockLink            structure in addition to the requested amount of bytes. */            if( xWantedSize > 0 )            {                xWantedSize = xPortWantedSizeAlign(xWantedSize);            }            if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )            {                /* Traverse the list from the start	(lowest address) block until                one	of adequate size is found. */                pxPreviousBlock = &xStart;                pxBlock = xStart.pxNextFreeBlock;                while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )                {                    pxPreviousBlock = pxBlock;                    pxBlock = pxBlock->pxNextFreeBlock;                }                /* If the end marker was reached then a block of adequate size                was	not found. */                if( pxBlock != pxEnd )                {                    /* Return the memory space pointed to - jumping over the                    xBlockLink structure at its start. */                    pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );                    /* This block is being returned for use so must be taken out                    of the list of free blocks. */                    pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;                    /* If the block is larger than required it can be split into                    two. */                    if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )                    {                        /* This block is to be split into two.  Create a new                        block following the number of bytes requested. The void                        cast is used to prevent byte alignment warnings from the                        compiler. */                        pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );                        /* Calculate the sizes of two blocks split from the                        single block. */                        pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;                        pxBlock->xBlockSize = xWantedSize;                        /* Insert the new block into the list of free blocks. */                        prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );                    }                    xFreeBytesRemaining -= pxBlock->xBlockSize;                    /* The block is being returned - it is allocated and owned                    by the application and has no "next" block. */                    pxBlock->xBlockSize |= xBlockAllocatedBit;                    pxBlock->pxNextFreeBlock = NULL;                }            }        }    }//	xTaskResumeAll();    ETS_INTR_UNLOCK();#if( configUSE_MALLOC_FAILED_HOOK == 1 )    {        if( pvReturn == NULL )        {            extern void vApplicationMallocFailedHook( void );            vApplicationMallocFailedHook();        }    }#endif//    printf("%s %x %x/n", __func__, pvReturn, pxBlock);    return pvReturn;}
开发者ID:flexiti,项目名称:esp8266-devkit,代码行数:99,


示例15: taskENTER_CRITICAL

void *pvPortMalloc( size_t xWantedSize ){xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink;void *pvReturn = NULL;	taskENTER_CRITICAL( &xMemLock );	{		/* If this is the first call to malloc then the heap will require		initialisation to setup the list of free blocks. */		if( pxEnd == NULL )		{			prvHeapInit();		}		/* The wanted size is increased so it can contain a xBlockLink		structure in addition to the requested amount of bytes. */		if( xWantedSize > 0 )		{			xWantedSize += heapSTRUCT_SIZE;			/* Ensure that blocks are always aligned to the required number of 			bytes. */			if( xWantedSize & portBYTE_ALIGNMENT_MASK )			{				/* Byte alignment required. */				xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );			}		}		if( ( xWantedSize > 0 ) && ( xWantedSize < xTotalHeapSize ) )		{			/* Traverse the list from the start	(lowest address) block until one			of adequate size is found. */			pxPreviousBlock = &xStart;			pxBlock = xStart.pxNextFreeBlock;			while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )			{				pxPreviousBlock = pxBlock;				pxBlock = pxBlock->pxNextFreeBlock;			}			/* If the end marker was reached then a block of adequate size was			not found. */			if( pxBlock != pxEnd )			{				/* Return the memory space - jumping over the xBlockLink structure				at its start. */				pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );				/* This block is being returned for use so must be taken out of				the	list of free blocks. */				pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;				/* If the block is larger than required it can be split into two. */				if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )				{					/* This block is to be split into two.  Create a new block					following the number of bytes requested. The void cast is					used to prevent byte alignment warnings from the compiler. */					pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );					/* Calculate the sizes of two blocks split from the single					block. */					pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;					pxBlock->xBlockSize = xWantedSize;					/* Insert the new block into the list of free blocks. */					prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );				}				xFreeBytesRemaining -= pxBlock->xBlockSize;			}		}	}	taskEXIT_CRITICAL( &xMemLock );	#if( configUSE_MALLOC_FAILED_HOOK == 1 )	{		if( pvReturn == NULL )		{			extern void vApplicationMallocFailedHook( void );			vApplicationMallocFailedHook();		}	}	#endif	return pvReturn;}
开发者ID:HackLinux,项目名称:freertos-multicore,代码行数:88,



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


C++ vApplicationSetupTimerInterrupt函数代码示例
C++ vAltStartComTestTasks函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。