FILLHEAP.C
资源名称:C.rar [点击查看]
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:1k
源码类别:
界面编程
开发平台:
C/C++
- #include <stdio.h>
- #include <alloc.h>
- void main(void)
- {
- char *buffer1, *buffer2, *buffer3;
- int i, state;
- buffer1 = malloc(100);
- buffer2 = malloc(200);
- buffer3 = malloc(300);
- free(buffer2); // Free space in the middle
- state = heapfillfree('A');
- if (state == _HEAPOK)
- printf("Heap is okn");
- else if (state == _HEAPCORRUPT)
- printf("Heap is corruptn");
- for (i = 0; i <= 150; i++)
- buffer1[i] = i;
- state = heapcheckfree('A');
- if (state == _HEAPOK)
- printf("Heap is okn");
- else if (state == _HEAPCORRUPT)
- printf("Heap is corruptn");
- else if (state == _BADVALUE)
- printf("Value has been changed in free spacen");
- }