Advertisement
vim_fans

Untitled

Dec 22nd, 2021
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #define ALLOCSIZE 10000 /* size of available space */
  2.  
  3. static char allocbuf[ALLOCSIZE]; /* storage for alloc */
  4. static char *allocp = allocbuf; /* next free position */
  5.  
  6.  
  7. char *alloc(int n)  /* return pointer to n characters */
  8. {
  9.     if(allocbuf + ALLOCSIZE - allocp >= n){  /* it fits */
  10.         allocp+=n;
  11.         return allocp - n;  /* old p */
  12.     } else                     /* not enough room */
  13.         return 0;
  14.    
  15. }
  16.  
  17.  
  18. void afree(char *p)  /*free storage pointed to by p */
  19. {
  20.     if(p >= allocbuf && p < allocbuf + ALLOCSIZE)
  21.         allocp = p;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement