/gecko_api/include/nsIMemory.h

http://firefox-mac-pdf.googlecode.com/ · C Header · 214 lines · 80 code · 34 blank · 100 comment · 0 complexity · f9cdc521fb3c71f31be53a27ed221b73 MD5 · raw file

  1. /*
  2. * DO NOT EDIT. THIS FILE IS GENERATED FROM /builds/tinderbox/XR-Trunk/Darwin_8.8.4_Depend/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 NS_SCRIPTABLE nsIMemory : public nsISupports {
  52. public:
  53. NS_DECLARE_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_SCRIPTABLE 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_SCRIPTABLE NS_IMETHOD IsLowMemory(PRBool *_retval) = 0;
  106. };
  107. NS_DEFINE_STATIC_IID_ACCESSOR(nsIMemory, NS_IMEMORY_IID)
  108. /* Use this macro when declaring classes that implement this interface. */
  109. #define NS_DECL_NSIMEMORY \
  110. NS_IMETHOD_(void *) Alloc(size_t size); \
  111. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize); \
  112. NS_IMETHOD_(void) Free(void * ptr); \
  113. NS_SCRIPTABLE NS_IMETHOD HeapMinimize(PRBool immediate); \
  114. NS_SCRIPTABLE NS_IMETHOD IsLowMemory(PRBool *_retval);
  115. /* Use this macro to declare functions that forward the behavior of this interface to another object. */
  116. #define NS_FORWARD_NSIMEMORY(_to) \
  117. NS_IMETHOD_(void *) Alloc(size_t size) { return _to Alloc(size); } \
  118. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize) { return _to Realloc(ptr, newSize); } \
  119. NS_IMETHOD_(void) Free(void * ptr) { return _to Free(ptr); } \
  120. NS_SCRIPTABLE NS_IMETHOD HeapMinimize(PRBool immediate) { return _to HeapMinimize(immediate); } \
  121. NS_SCRIPTABLE NS_IMETHOD IsLowMemory(PRBool *_retval) { return _to IsLowMemory(_retval); }
  122. /* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
  123. #define NS_FORWARD_SAFE_NSIMEMORY(_to) \
  124. NS_IMETHOD_(void *) Alloc(size_t size) { return !_to ? NS_ERROR_NULL_POINTER : _to->Alloc(size); } \
  125. NS_IMETHOD_(void *) Realloc(void * ptr, size_t newSize) { return !_to ? NS_ERROR_NULL_POINTER : _to->Realloc(ptr, newSize); } \
  126. NS_IMETHOD_(void) Free(void * ptr) { return !_to ? NS_ERROR_NULL_POINTER : _to->Free(ptr); } \
  127. NS_SCRIPTABLE NS_IMETHOD HeapMinimize(PRBool immediate) { return !_to ? NS_ERROR_NULL_POINTER : _to->HeapMinimize(immediate); } \
  128. NS_SCRIPTABLE NS_IMETHOD IsLowMemory(PRBool *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->IsLowMemory(_retval); }
  129. #if 0
  130. /* Use the code below as a template for the implementation class for this interface. */
  131. /* Header file */
  132. class nsMemory : public nsIMemory
  133. {
  134. public:
  135. NS_DECL_ISUPPORTS
  136. NS_DECL_NSIMEMORY
  137. nsMemory();
  138. private:
  139. ~nsMemory();
  140. protected:
  141. /* additional members */
  142. };
  143. /* Implementation file */
  144. NS_IMPL_ISUPPORTS1(nsMemory, nsIMemory)
  145. nsMemory::nsMemory()
  146. {
  147. /* member initializers and constructor code */
  148. }
  149. nsMemory::~nsMemory()
  150. {
  151. /* destructor code */
  152. }
  153. /* [noscript, notxpcom] voidPtr alloc (in size_t size); */
  154. NS_IMETHODIMP_(void *) nsMemory::Alloc(size_t size)
  155. {
  156. return NS_ERROR_NOT_IMPLEMENTED;
  157. }
  158. /* [noscript, notxpcom] voidPtr realloc (in voidPtr ptr, in size_t newSize); */
  159. NS_IMETHODIMP_(void *) nsMemory::Realloc(void * ptr, size_t newSize)
  160. {
  161. return NS_ERROR_NOT_IMPLEMENTED;
  162. }
  163. /* [noscript, notxpcom] void free (in voidPtr ptr); */
  164. NS_IMETHODIMP_(void) nsMemory::Free(void * ptr)
  165. {
  166. return NS_ERROR_NOT_IMPLEMENTED;
  167. }
  168. /* void heapMinimize (in boolean immediate); */
  169. NS_IMETHODIMP nsMemory::HeapMinimize(PRBool immediate)
  170. {
  171. return NS_ERROR_NOT_IMPLEMENTED;
  172. }
  173. /* boolean isLowMemory (); */
  174. NS_IMETHODIMP nsMemory::IsLowMemory(PRBool *_retval)
  175. {
  176. return NS_ERROR_NOT_IMPLEMENTED;
  177. }
  178. /* End of implementation class template. */
  179. #endif
  180. #endif /* __gen_nsIMemory_h__ */