clear.c 720 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* clear - clear a block of memory, and try to do it fast.
  7. */
  8. #include "alloc.h"
  9. /* instead of Calloc: */
  10. void
  11. clear(ptr, n)
  12. register char *ptr;
  13. register unsigned int n;
  14. {
  15. register long *q = (long *) ptr;
  16. while (n >= 8*sizeof (long)) {
  17. /* high-speed clear loop */
  18. *q++ = 0;
  19. *q++ = 0;
  20. *q++ = 0;
  21. *q++ = 0;
  22. *q++ = 0;
  23. *q++ = 0;
  24. *q++ = 0;
  25. *q++ = 0;
  26. n -= 8*sizeof (long);
  27. }
  28. while (n >= sizeof (long)) {
  29. /* high-speed clear loop */
  30. *q++ = 0;
  31. n -= sizeof (long);
  32. }
  33. ptr = (char *) q;
  34. while (n--) *ptr++ = '\0';
  35. }