날마다 새롭게 또 날마다 새롭게

alloc - 메모리 할당/해제 함수 구현 코드(stack, 포인터 연산) 본문

프로그래밍/C / C++

alloc - 메모리 할당/해제 함수 구현 코드(stack, 포인터 연산)

아무유 2013. 3. 15. 21:35

#define ALLOCSIZE 10000    /* size of available space */

static char allocbuf[ALLOCSIZE];    /* storage for alloc */

static char *allocp = allocbuf;           /* next free position */

char *alloc(int n)    /* return pointer to n characters */

{

if(allocbuf + ALLOCSIZE - allocp >= n)

{

allocp += n;

return allocp - n;

} else

return 0;

}


void afree(char *p)

{    

if(p >= allocbuf && p < allocbuf + ALLOCSIZE)

allocp = p;

}

Comments