不说废话,先上示例代码
uint8_t num_byte[4];
uint32_t num_word;
const uint32_t num_word_const = 0x1234;
uint32_t *point_heap;
int main(void)
{
uint8_t num_byte_stack;
static uint8_t num_byte_static;
point_heap = (uint32_t *)malloc(4);
*point_heap = 0x3421;
free(point_heap);
num_byte_stack = 0x11;
#pragma section = "CSTACK"
char *pbeginstk = __section_begin("CSTACK");
#pragma section = "HEAP"
char *pbeginheap = __section_begin("HEAP");
printf("CSTACK addr is 0x%x\r\n",pbeginstk);
printf("HEAP addr is 0x%x\r\n",pbeginheap);
printf("num_byte addr is 0x%x\r\n",&num_byte);
printf("num_word addr is 0x%x\r\n",&num_word);
printf("num_word_const addr is 0x%x\r\n",&num_word_const);
printf("point_heap addr is 0x%x\r\n",&point_heap);
printf("point_heap is 0x%x\r\n",point_heap);
printf("num_byte_stack addr is 0x%x\r\n",&num_byte_stack);
printf("num_byte_static addr is 0x%x\r\n",&num_byte_static);
}
打印如下
STACK addr is 0x20000320
HEAP addr is 0x20000720
num_byte addr is 0x20000308
num_word addr is 0x2000030c
num_word_const addr is 0x8002a44
point_heap addr is 0x20000310
point_heap is 0x20000728
num_byte_stack addr is 0x200006f8
num_byte_static addr is 0x20000318
先说结论: num_byte、num_word、num_byte_static和point_heap存储在内部RAM中。 num_byte_stack存贮在栈中。 point_heap申请到的内存在堆中。 num_word_const在内部flash中。 如果是有同学对这个了然于胸,可以出门左转了,如果有些同学有兴趣,可以进一步往下看。
|