#include
#include
#define HEAP_BLOCK_SIZE 32
int main()
{
// 分配申明 heap 内存块 1
char *pbuf1 = (char *) malloc(HEAP_BLOCK_SIZE);
printf("HeapTest block 1 (%d bytes) at %08Xh", sizeof(pbuf1), pbuf1);
*pbuf1 = '1';
//分配申明 heap 内存块 2
char *pbuf2 = (char *) malloc(HEAP_BLOCK_SIZE);
printf("HeapTest block 2 (%d bytes) at %08Xh", sizeof(pbuf2), pbuf2);
*pbuf2 = '2';
//分配申明 heap 内存块 3
char *pbuf3 = (char *) malloc(HEAP_BLOCK_SIZE);
printf("HeapTest block 3 (%d bytes) at %08Xh", sizeof(pbuf3), pbuf3);
*pbuf3 = '3';
// 释放 heap 内存块 1
printf("HeapTest block 1 (%d bytes) at %08Xh freed",sizeof(pbuf1), pbuf1);
free(pbuf1);
//释放 heap 内存块 2
printf("HeapTest block 2 (%d bytes) at %08Xh freed",sizeof(pbuf2), pbuf2);
free(pbuf2);
//释放heap内存块 3
printf("HeapTest block 3 (%d bytes) at %08Xh freed",sizeof(pbuf3), pbuf3);
free(pbuf3);
//分配申明 heap 内存块 4
char *pbuf4 = (char *) malloc( HEAP_BLOCK_SIZE);
printf("HeapTest block 4 (%d bytes) at %08Xh", sizeof(pbuf4), pbuf4);
*pbuf4 = '4';
//分配申明 heap 内存块 5
char *pbuf5 = (char *) malloc( HEAP_BLOCK_SIZE);
printf("HeapTest block 5 (%d bytes) at %08Xh", sizeof(pbuf5), pbuf5);
*pbuf5 = '5';
//分配申明 heap 内存块 6
char *pbuf6 = (char *) malloc( HEAP_BLOCK_SIZE);
printf("HeapTest block 6 (%d bytes) at %08Xh", sizeof(pbuf6), pbuf6);
*pbuf6= '6';
//休眠时间过长,可注释掉循环
for(;;) {
Sleep(1000);
}
return 0;
}
第一,vi/vim师编辑器不是编译器,Linux下的编译需要手动的;第二,我想知道你是怎么编译的,能提供你所写的命令吗?