apr_allocator.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {
  17. * @file apr_allocator.h
  18. * @brief APR Internal Memory Allocation
  19. }
  20. {#include "apr.h"
  21. #include "apr_errno.h"
  22. #define APR_WANT_MEMFUNC < For no good reason?
  23. #include "apr_want.h"}
  24. {
  25. * @defgroup apr_allocator Internal Memory Allocation
  26. * @ingroup APR
  27. }
  28. type
  29. { the allocator structure }
  30. apr_allocator_t = record end;
  31. Papr_allocator_t = ^apr_allocator_t;
  32. PPapr_allocator_t = ^Papr_allocator_t;
  33. { the structure which holds information about the allocation }
  34. Papr_memnode_t = ^apr_memnode_t;
  35. PPapr_memnode_t = ^Papr_memnode_t;
  36. { basic memory node structure }
  37. apr_memnode_t = record
  38. next: Papr_memnode_t; {< next memnode }
  39. ref: PPapr_memnode_t; {< reference to self }
  40. index: apr_uint32_t; {< size }
  41. free_index: apr_uint32_t; {< how much free }
  42. first_avail: PChar; {< pointer to first free memory }
  43. endp: PChar; {< pointer to end of free memory }
  44. end;
  45. { The base size of a memory node - aligned. }
  46. //#define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t))
  47. { Symbolic constants }
  48. const
  49. APR_ALLOCATOR_MAX_FREE_UNLIMITED = 0;
  50. {
  51. * Create a new allocator
  52. * @param allocator The allocator we have just created.
  53. *
  54. }
  55. function apr_allocator_create(allocator: PPapr_allocator_t): apr_status_t;
  56. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  57. external LibAPR name LibNamePrefix + 'apr_allocator_create' + LibSuff4;
  58. {
  59. * Destroy an allocator
  60. * @param allocator The allocator to be destroyed
  61. * @remark Any memnodes not given back to the allocator prior to destroying
  62. * will _not_ be free()d.
  63. }
  64. procedure apr_allocator_destroy(allocator: Papr_allocator_t);
  65. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  66. external LibAPR name LibNamePrefix + 'apr_allocator_destroy' + LibSuff4;
  67. {
  68. * Allocate a block of mem from the allocator
  69. * @param allocator The allocator to allocate from
  70. * @param size The size of the mem to allocate (excluding the
  71. * memnode structure)
  72. }
  73. function apr_allocator_alloc(allocator: Papr_allocator_t;
  74. size: apr_size_t): Papr_memnode_t;
  75. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  76. external LibAPR name LibNamePrefix + 'apr_allocator_alloc' + LibSuff8;
  77. {
  78. * Free a block of mem, giving it back to the allocator
  79. * @param allocator The allocator to give the mem back to
  80. * @param memnode The memory node to return
  81. }
  82. procedure apr_allocator_free(allocator: Papr_allocator_t; memnode: Papr_memnode_t);
  83. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  84. external LibAPR name LibNamePrefix + 'apr_allocator_free' + LibSuff8;
  85. //#include "apr_pools.h"
  86. {
  87. * Set the owner of the allocator
  88. * @param allocator The allocator to set the owner for
  89. * @param pool The pool that is to own the allocator
  90. * @remark Typically pool is the highest level pool using the allocator
  91. }
  92. {
  93. * XXX: see if we can come up with something a bit better. Currently
  94. * you can make a pool an owner, but if the pool doesn't use the allocator
  95. * the allocator will never be destroyed.
  96. }
  97. procedure apr_allocator_owner_set(allocator: Papr_allocator_t; pool: Papr_pool_t);
  98. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  99. external LibAPR name LibNamePrefix + 'apr_allocator_owner_set' + LibSuff8;
  100. { @deprecated @see apr_allocator_owner_set }
  101. {APR_DECLARE(void) apr_allocator_set_owner(apr_allocator_t *allocator,
  102. apr_pool_t *pool);
  103. }
  104. {
  105. * Get the current owner of the allocator
  106. * @param allocator The allocator to get the owner from
  107. }
  108. function apr_allocator_owner_get(allocator: Papr_allocator_t): Papr_pool_t;
  109. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  110. external LibAPR name LibNamePrefix + 'apr_allocator_owner_get' + LibSuff4;
  111. { @deprecated @see apr_allocator_owner_get }
  112. {APR_DECLARE(apr_pool_t *) apr_allocator_get_owner(
  113. apr_allocator_t *allocator);
  114. }
  115. {
  116. * Set the current threshold at which the allocator should start
  117. * giving blocks back to the system.
  118. * @param allocator The allocator the set the threshold on
  119. * @param size The threshold. 0 == unlimited.
  120. }
  121. procedure apr_allocator_max_free_set(allocator: Papr_allocator_t; size: apr_size_t);
  122. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  123. external LibAPR name LibNamePrefix + 'apr_allocator_max_free_set' + LibSuff8;
  124. { @deprecated @see apr_allocator_max_free_set }
  125. {APR_DECLARE(void) apr_allocator_set_max_free(apr_allocator_t *allocator,
  126. apr_size_t size);
  127. #include "apr_thread_mutex.h"}
  128. {$ifdef APR_HAS_THREADS}
  129. {
  130. * Set a mutex for the allocator to use
  131. * @param allocator The allocator to set the mutex for
  132. * @param mutex The mutex
  133. }
  134. APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator,
  135. apr_thread_mutex_t *mutex);
  136. { @deprecated @see apr_allocator_mutex_set }
  137. APR_DECLARE(void) apr_allocator_set_mutex(apr_allocator_t *allocator,
  138. apr_thread_mutex_t *mutex);
  139. {
  140. * Get the mutex currently set for the allocator
  141. * @param allocator The allocator
  142. }
  143. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get(
  144. apr_allocator_t *allocator);
  145. { @deprecated @see apr_allocator_mutex_get }
  146. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_get_mutex(
  147. apr_allocator_t *allocator);
  148. {$endif} { APR_HAS_THREADS }