home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdlib / malloc.txh < prev    next >
Encoding:
Text File  |  1995-07-10  |  1.8 KB  |  88 lines

  1. @node malloc, memory
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <stdlib.h>
  6.  
  7. void *malloc(size_t size);
  8. @end example
  9.  
  10. @subheading Description
  11.  
  12. This function allocates a chunk of memory from the heap large enough to
  13. hold any object that is @var{size} bytes in length.  This memory must be
  14. returned to the heap with @code{free} (@pxref{free}). 
  15.  
  16. @subheading Return Value
  17.  
  18. A pointer to the allocated memory, or @code{NULL} if there isn't enough
  19. free memory to satisfy the request. 
  20.  
  21. @subheading Example
  22.  
  23. @example
  24. char *c = (char *)malloc(100);
  25. @end example
  26.  
  27. @c ----------------------------------------------------------------------
  28.  
  29. @node free, memory
  30. @subheading Syntax
  31.  
  32. @example
  33. #include <stdio.h>
  34.  
  35. void free(void *ptr);
  36. @end example
  37.  
  38. @subheading Description
  39.  
  40. Returns the allocated memory to the heap (@pxref{malloc}).  If the
  41. @var{ptr} is @code{NULL}, it does nothing. 
  42.  
  43. @subheading Return Value
  44.  
  45. None.
  46.  
  47. @subheading Example
  48.  
  49. @example
  50. char *q = (char *)malloc(20);
  51. free(q);
  52. @end example
  53.  
  54. @c ----------------------------------------------------------------------
  55.  
  56. @node realloc, memory
  57. @subheading Syntax
  58.  
  59. @example
  60. #include <stdlib.h>
  61.  
  62. void *realloc(void *ptr, size_t size);
  63. @end example
  64.  
  65. @subheading Description
  66.  
  67. This function changes the size of the region pointed to by @var{ptr}. 
  68. If it can, it will reuse the same memory space, but it may have to
  69. allocate a new memory space to satisfy the request.  In either case, it
  70. will return the pointer that you should use to refer to the (possibly
  71. new) memory area.  The pointer passed may be @code{NULL}, in which case
  72. this function acts just like @code{malloc} (@pxref{malloc}). 
  73.  
  74. @subheading Return Value
  75.  
  76. A pointer to the memory you should now refer to. 
  77.  
  78. @subheading Example
  79.  
  80. @example
  81. if (now+new > max)
  82. @{
  83.   max = now+new;
  84.   p = realloc(p, max);
  85. @}
  86. @end example
  87.  
  88.