nsIMemory.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * DO NOT EDIT. THIS FILE IS GENERATED FROM c:/mozilla/xpcom/base/nsIMemory.idl
  3. */
  4. #ifndef __gen_nsIMemory_h__
  5. #define __gen_nsIMemory_h__
  6. #ifndef __gen_nsISupports_h__
  7. #include "nsISupports.h"
  8. #endif
  9. /* For IDL files that don't want to include root IDL files. */
  10. #ifndef NS_NO_VTABLE
  11. #define NS_NO_VTABLE
  12. #endif
  13. /* starting interface: nsIMemory */
  14. #define NS_IMEMORY_IID_STR "59e7e77a-38e4-11d4-8cf5-0060b0fc14a3"
  15. #define NS_IMEMORY_IID \
  16. {0x59e7e77a, 0x38e4, 0x11d4, \
  17. { 0x8c, 0xf5, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3 }}
  18. /**
  19. *
  20. * nsIMemory: interface to allocate and deallocate memory. Also provides
  21. * for notifications in low-memory situations.
  22. *
  23. * The frozen exported symbols NS_Alloc, NS_Realloc, and NS_Free
  24. * provide a more efficient way to access XPCOM memory allocation. Using
  25. * those symbols is preferred to using the methods on this interface.
  26. *
  27. * A client that wishes to be notified of low memory situations (for
  28. * example, because the client maintains a large memory cache that
  29. * could be released when memory is tight) should register with the
  30. * observer service (see nsIObserverService) using the topic
  31. * "memory-pressure". There are three specific types of notications
  32. * that can occur. These types will be passed as the |aData|
  33. * parameter of the of the "memory-pressure" notification:
  34. *
  35. * "low-memory"
  36. * This will be passed as the extra data when the pressure
  37. * observer is being asked to flush for low-memory conditions.
  38. *
  39. * "heap-minimize"
  40. * This will be passed as the extra data when the pressure
  41. * observer is being asked to flush because of a heap minimize
  42. * call.
  43. *
  44. * "alloc-failure"
  45. * This will be passed as the extra data when the pressure
  46. * observer has been asked to flush because a malloc() or
  47. * realloc() has failed.
  48. *
  49. * @status FROZEN
  50. */
  51. class NS_NO_VTABLE nsIMemory : public nsISupports {
  52. public:
  53. NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMEMORY_IID)
  54. /**
  55. * Allocates a block of memory of a particular size. If the memory
  56. * cannot be allocated (because of an out-of-memory condition), null
  57. * is returned.
  58. *
  59. * @param size - the size of the block to allocate
  60. * @result the block of memory
  61. */
  62. /* [noscript, notxpcom] voidPtr alloc (in size_t size); */
  63. NS_IMETHOD_(void *) Alloc(size_t size) = 0;
  64. /**
  65. * Reallocates a block of memory to a new size.
  66. *
  67. * @param ptr - the block of memory to reallocate
  68. * @param size - the new size
  69. * @result the reallocated block of memory
  70. *
  71. * If ptr is null, this function behaves like malloc.
  72. * If s is the size of the block to which ptr points, the first
  73. * min(s, size) bytes of ptr's block are copied to the new block.
  74. * If the allocation succeeds, ptr is freed and a pointer to the
  75. * new block returned. If the allocation fails, ptr is not freed
  76. * and null is returned. The returned value may be the same as ptr.
  77. */
  78. /* [noscript, notxpcom] voidPtr realloc (in voidPtr ptr, in size_t newSize); */
  79. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize) = 0;
  80. /**
  81. * Frees a block of memory. Null is a permissible value, in which case
  82. * nothing happens.
  83. *
  84. * @param ptr - the block of memory to free
  85. */
  86. /* [noscript, notxpcom] void free (in voidPtr ptr); */
  87. NS_IMETHOD_(void) Free(void * ptr) = 0;
  88. /**
  89. * Attempts to shrink the heap.
  90. * @param immediate - if true, heap minimization will occur
  91. * immediately if the call was made on the main thread. If
  92. * false, the flush will be scheduled to happen when the app is
  93. * idle.
  94. * @return NS_ERROR_FAILURE if 'immediate' is set an the call
  95. * was not on the application's main thread.
  96. */
  97. /* void heapMinimize (in boolean immediate); */
  98. NS_IMETHOD HeapMinimize(PRBool immediate) = 0;
  99. /**
  100. * This predicate can be used to determine if we're in a low-memory
  101. * situation (what constitutes low-memory is platform dependent). This
  102. * can be used to trigger the memory pressure observers.
  103. */
  104. /* boolean isLowMemory (); */
  105. NS_IMETHOD IsLowMemory(PRBool *_retval) = 0;
  106. };
  107. /* Use this macro when declaring classes that implement this interface. */
  108. #define NS_DECL_NSIMEMORY \
  109. NS_IMETHOD_(void *) Alloc(size_t size); \
  110. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize); \
  111. NS_IMETHOD_(void) Free(void * ptr); \
  112. NS_IMETHOD HeapMinimize(PRBool immediate); \
  113. NS_IMETHOD IsLowMemory(PRBool *_retval);
  114. /* Use this macro to declare functions that forward the behavior of this interface to another object. */
  115. #define NS_FORWARD_NSIMEMORY(_to) \
  116. NS_IMETHOD_(void *) Alloc(size_t size) { return _to Alloc(size); } \
  117. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize) { return _to Realloc(ptr, newSize); } \
  118. NS_IMETHOD_(void) Free(void * ptr) { return _to Free(ptr); } \
  119. NS_IMETHOD HeapMinimize(PRBool immediate) { return _to HeapMinimize(immediate); } \
  120. NS_IMETHOD IsLowMemory(PRBool *_retval) { return _to IsLowMemory(_retval); }
  121. /* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
  122. #define NS_FORWARD_SAFE_NSIMEMORY(_to) \
  123. NS_IMETHOD_(void *) Alloc(size_t size) { return !_to ? NS_ERROR_NULL_POINTER : _to->Alloc(size); } \
  124. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize) { return !_to ? NS_ERROR_NULL_POINTER : _to->Realloc(ptr, newSize); } \
  125. NS_IMETHOD_(void) Free(void * ptr) { return !_to ? NS_ERROR_NULL_POINTER : _to->Free(ptr); } \
  126. NS_IMETHOD HeapMinimize(PRBool immediate) { return !_to ? NS_ERROR_NULL_POINTER : _to->HeapMinimize(immediate); } \
  127. NS_IMETHOD IsLowMemory(PRBool *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->IsLowMemory(_retval); }
  128. #if 0
  129. /* Use the code below as a template for the implementation class for this interface. */
  130. /* Header file */
  131. class nsMemory : public nsIMemory
  132. {
  133. public:
  134. NS_DECL_ISUPPORTS
  135. NS_DECL_NSIMEMORY
  136. nsMemory();
  137. private:
  138. ~nsMemory();
  139. protected:
  140. /* additional members */
  141. };
  142. /* Implementation file */
  143. NS_IMPL_ISUPPORTS1(nsMemory, nsIMemory)
  144. nsMemory::nsMemory()
  145. {
  146. /* member initializers and constructor code */
  147. }
  148. nsMemory::~nsMemory()
  149. {
  150. /* destructor code */
  151. }
  152. /* [noscript, notxpcom] voidPtr alloc (in size_t size); */
  153. NS_IMETHODIMP_(void *) nsMemory::Alloc(size_t size)
  154. {
  155. return NS_ERROR_NOT_IMPLEMENTED;
  156. }
  157. /* [noscript, notxpcom] voidPtr realloc (in voidPtr ptr, in size_t newSize); */
  158. NS_IMETHODIMP_(void *) nsMemory::Realloc(void * ptr, size_t newSize)
  159. {
  160. return NS_ERROR_NOT_IMPLEMENTED;
  161. }
  162. /* [noscript, notxpcom] void free (in voidPtr ptr); */
  163. NS_IMETHODIMP_(void) nsMemory::Free(void * ptr)
  164. {
  165. return NS_ERROR_NOT_IMPLEMENTED;
  166. }
  167. /* void heapMinimize (in boolean immediate); */
  168. NS_IMETHODIMP nsMemory::HeapMinimize(PRBool immediate)
  169. {
  170. return NS_ERROR_NOT_IMPLEMENTED;
  171. }
  172. /* boolean isLowMemory (); */
  173. NS_IMETHODIMP nsMemory::IsLowMemory(PRBool *_retval)
  174. {
  175. return NS_ERROR_NOT_IMPLEMENTED;
  176. }
  177. /* End of implementation class template. */
  178. #endif
  179. #endif /* __gen_nsIMemory_h__ */