- 博客(1)
- 资源 (3)
- 收藏
- 关注
原创 npuctf
NPUCTF 复现 CTF WP 计算机网络 CTF 学习总结 密码学 操作系统 NPUCTF 复现 2个月前 / 0评 / 1赞 赏 码比赛的时候运维太差了,所以就想着赛后复现一下。Table of Contents[NPUCTF2020]ReadlezPHP[NPUCTF2020]ezlogin[NPUCTF2020]验证????[NPUCTF
2020-06-26 16:16:42
781
C语言高级编程及实例部.rar
例1:本节给出三个非常实用和高速的内存分配函数。读者可以直接拷贝这三个函数到程序中去,使用Allocate()和My_Free()代替系统提供的alloc()和free()函数。调试环境为TC2.0或者TC3.0
/*
FILE: ALLOCATE.C
*/
#define PRIVATE static /* Used to hide identifiers from BIND */
#define BLKSIZ 80 /* Size of allocation block */
#define STKSIZ 1000 /* Bytes reserved for stack */
#define MLCSIZ 3000 /* Bytes reserved for malloc() */
typedef union
{
char *link ;
char data[BLKSIZ] ;
} BLOCK ;
PRIVATE char *btm_of_heap ;
PRIVATE char *top_of_heap ;
PRIVATE BLOCK *heap ;
void Init_Heap()
{
unsigned *ptr ;
unsigned size ;
unsigned blk ;
unsigned ttl_blks ;
freeall(STKSIZ) ; /* Reserve a stack of 500 words */
ptr = _memory() + 1 ; /* Get pointer to heap size */
size = *ptr ; /* Get size of heap */
size -= MLCSIZ ; /* Keep 3K for malloc() */
ttl_blks = size/sizeof(BLOCK) ; /* # available blocks */
size = sizeof(BLOCK)*ttl_blks ; /* Use an even multiple */
btm_of_heap = malloc(size) ; /* Reserve the blocks */
heap = btm_of_heap ; /* Form the free list */
for (blk = 0 ; blk < ttl_blks - 1; blk++)
{
heap->link = heap + 1 ;
heap++ ;
}
heap->link = 0 ; /* Establish end marker */
heap = btm_of_heap ; /* Restore head pointer */
top_of_heap = &heap[ttl_blks] ; /* 1st malloc() block */
}
void My_Free(ptr)
BLOCK *ptr ;
{
if (ptr >= btm_of_heap)
{
if (ptr < top_of_heap) /* Block is from my heap */
{
ptr->link = heap ;
heap = ptr ;
return ;
}
else if (free(ptr)) /* Block is from C-Ware's heap */
{
return ;
}
}
puts("\nAttempt to free unallocated block!\n\7") ;
exit(1) ;
}
char *Allocate(bytes)
unsigned bytes ;
{
BLOCK *ptr ;
if (bytes <= BLKSIZ) /* Block will fit in my size */
{
if (heap != 0) /* Any free blocks? */
{
ptr = heap ;
heap = heap->link ;
return ptr ;
}
}
if (ptr = malloc(bytes)) /* Won't fit or none left! */
{
return ptr ;
}
puts("Insufficient memory: malloc()\n\7") ;
exit(1) ;
}
2009-04-22
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人