xalloc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. .TH XALLOC 9
  2. .SH NAME
  3. xalloc, xspanalloc, xfree \- basic memory management
  4. .SH SYNOPSIS
  5. .ta \w'\fLvoid* 'u
  6. .B
  7. void* xalloc(ulong size)
  8. .PP
  9. .B
  10. void* xspanalloc(ulong size, int align, ulong span)
  11. .PP
  12. .B
  13. void xfree(void *p)
  14. .SH DESCRIPTION
  15. .I Xalloc
  16. and
  17. .I xfree
  18. are primitives used by higher-level memory allocators in the kernel,
  19. such as
  20. .IR malloc (9).
  21. They are not intended for use directly by most kernel routines.
  22. The main exceptions are routines that permanently allocate large structures,
  23. or need the special alignment properties guaranteed by
  24. .IR xspanalloc .
  25. .PP
  26. .I Xalloc
  27. returns a pointer to a range of size bytes of memory. The memory will be zero filled and aligned on a 8 byte
  28. .RB ( BY2V )
  29. address. If the memory is not available,
  30. .B xalloc
  31. returns a null pointer.
  32. .PP
  33. .I Xspanalloc
  34. allocates memory given alignment and spanning constraints.
  35. The block returned will contain
  36. .I size
  37. bytes, aligned on a boundary that is
  38. .BI "0 mod" " align,"
  39. in such a way that the memory in the block does not
  40. span an address that is
  41. .BI "0 mod" " span."
  42. .I Xspanalloc
  43. is intended for use
  44. allocating hardware data structures (eg, page tables) or I/O buffers
  45. that must satisfy specific alignment restrictions.
  46. If
  47. .I xspanalloc
  48. cannot allocate memory to satisfy the given constraints, it will
  49. .IR panic (9).
  50. The technique it uses can sometimes cause memory to be wasted.
  51. Consequently,
  52. .I xspanalloc
  53. should be used sparingly.
  54. .PP
  55. .I Xfree
  56. frees the block of memory at
  57. .IR p ,
  58. which must be an address previously returned by
  59. .I xalloc
  60. (not
  61. .IR xspanalloc ).
  62. .SS Allocation status
  63. Some memory allocation statistics are written to the console in response to
  64. the debugging sequence
  65. .LR "control-T control-T x" .
  66. The output includes the total free space, the number of free holes,
  67. and a summary of active holes.
  68. Each line shows `address top size'.
  69. .SH SOURCE
  70. .B /sys/src/9/port/xalloc.c
  71. .SH SEE ALSO
  72. .IR malloc (9)