# 堆和栈

堆是空闲的内存。

char heap_buf[1024];
int pos = 0;

void *my_malloc(int size)
{
    int old_pos = pos;
    pos += size;
    return &heap_buf[old_pos];
}

void my_free(void *buf)
{

}

int main(void)
{
    char ch = 65;
    char *buf = my_malloc(100);
    uint8_t uch = 200;

    for (int i = 0; i < 26; i++)
    {
        buf[i] = 'A' + i;
    }

    my_free();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

最后更新: 2023/8/14 14:33:35