home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / app / app_alloc.c next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  1.8 KB  |  69 lines

  1. /* 
  2. ** Unix-style hassle free memory allocation
  3. ** via Intuition's Alloc/FreeRemember functions.
  4. ** Copyright (C) 1998 David Benn
  5. ** 
  6. ** This program is free software; you can redistribute it and/or
  7. ** modify it under the terms of the GNU General Public License
  8. ** as published by the Free Software Foundation; either version 2
  9. ** of the License, or (at your option) any later version.
  10. **
  11. ** This program is distributed in the hope that it will be useful,
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ** GNU General Public License for more details.
  15. **
  16. ** You should have received a copy of the GNU General Public License
  17. ** along with this program; if not, write to the Free Software
  18. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19. **
  20. ** Call alloc for each memory allocation request.
  21. **
  22. ** Call free_alloc once at the end of the program run.
  23. **
  24. ** Author: David J Benn
  25. **   Date: 30th June 1993, 
  26. **       1st July 1993, 
  27. **           16th,24th,25th December 1993
  28. */
  29.  
  30. #include <exec/types.h>
  31. #include <exec/memory.h>
  32. #include <intuition/intuition.h>
  33.  
  34. /* local variables */
  35. struct Remember *RememberList = NULL;
  36. struct Library    *IntuitionBase = NULL;
  37.  
  38. /* functions */
  39. void open_intui_lib()
  40. {
  41. /* open Intuition Library */
  42.  
  43.  IntuitionBase = (struct Library *)OpenLibrary("intuition.library",0L);
  44.  if (IntuitionBase == NULL) 
  45.     { puts("Can't open intuition.library!"); exit(10); } 
  46. }
  47.  
  48. void *alloc(bytes,flags)
  49. ULONG bytes,flags;
  50. {
  51. /* allocate memory as requested */
  52.  
  53.  return((void *)AllocRemember(&RememberList,bytes,flags));     
  54. }
  55.  
  56. void free_alloc()
  57. {
  58. /* free all memory allocated by alloc 
  59.    and close intuition library */
  60.  
  61.  if (RememberList) 
  62.  {
  63.     FreeRemember(&RememberList,TRUE);
  64.     RememberList = NULL;
  65.  }
  66.  
  67.  if (IntuitionBase) CloseLibrary(IntuitionBase);
  68. }
  69.