Memory management FreeRTOS内存管理方案1-请求了解内存对齐的帮助

Memory management FreeRTOS内存管理方案1-请求了解内存对齐的帮助,memory-management,arm,memory-alignment,freertos,cortex-m,Memory Management,Arm,Memory Alignment,Freertos,Cortex M,我试图理解freeRTOS中的内存分配方案1 在此函数中,使用以下代码 static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; static uint8_t *pucAlignedHeap = NULL; if( pucAlignedHeap == NULL ) { /* Ensure the heap starts on a correctly aligned boundary. */

我试图理解freeRTOS中的内存分配方案1

在此函数中,使用以下代码

    static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
    static uint8_t *pucAlignedHeap = NULL;

    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 ) ) );
        }
我正在研究arm cortex m3 mcu。所以

portPOINTER_SIZE_TYPE defined as uint32_t
portBYTE_ALIGNMENT defined as 8 
portBYTE_ALIGNMENT_MASK defined as 0x0007
为什么不能只使用pucalingedheap=&ucHeap

感谢您的回答。

所有的处理器都这样做,因为C标准要求动态分配内存的起始地址与处理器的要求一致。您发布的代码正在进行对齐。很多代码都假设malloc是对齐的,所以使用它来存储必须对齐的项,而不必执行额外的检查,也不必分配比截断到对齐地址所需的更多的RAM