nsIMemory.idl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either of the GNU General Public License Version 2 or later (the "GPL"),
  26. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #include "nsISupports.idl"
  38. /**
  39. *
  40. * nsIMemory: interface to allocate and deallocate memory. Also provides
  41. * for notifications in low-memory situations.
  42. *
  43. * The frozen exported symbols NS_Alloc, NS_Realloc, and NS_Free
  44. * provide a more efficient way to access XPCOM memory allocation. Using
  45. * those symbols is preferred to using the methods on this interface.
  46. *
  47. * A client that wishes to be notified of low memory situations (for
  48. * example, because the client maintains a large memory cache that
  49. * could be released when memory is tight) should register with the
  50. * observer service (see nsIObserverService) using the topic
  51. * "memory-pressure". There are three specific types of notications
  52. * that can occur. These types will be passed as the |aData|
  53. * parameter of the of the "memory-pressure" notification:
  54. *
  55. * "low-memory"
  56. * This will be passed as the extra data when the pressure
  57. * observer is being asked to flush for low-memory conditions.
  58. *
  59. * "heap-minimize"
  60. * This will be passed as the extra data when the pressure
  61. * observer is being asked to flush because of a heap minimize
  62. * call.
  63. *
  64. * "alloc-failure"
  65. * This will be passed as the extra data when the pressure
  66. * observer has been asked to flush because a malloc() or
  67. * realloc() has failed.
  68. *
  69. * @status FROZEN
  70. */
  71. [scriptable, uuid(59e7e77a-38e4-11d4-8cf5-0060b0fc14a3)]
  72. interface nsIMemory : nsISupports
  73. {
  74. /**
  75. * Allocates a block of memory of a particular size. If the memory
  76. * cannot be allocated (because of an out-of-memory condition), null
  77. * is returned.
  78. *
  79. * @param size - the size of the block to allocate
  80. * @result the block of memory
  81. */
  82. [noscript, notxpcom] voidPtr alloc(in size_t size);
  83. /**
  84. * Reallocates a block of memory to a new size.
  85. *
  86. * @param ptr - the block of memory to reallocate
  87. * @param size - the new size
  88. * @result the reallocated block of memory
  89. *
  90. * If ptr is null, this function behaves like malloc.
  91. * If s is the size of the block to which ptr points, the first
  92. * min(s, size) bytes of ptr's block are copied to the new block.
  93. * If the allocation succeeds, ptr is freed and a pointer to the
  94. * new block returned. If the allocation fails, ptr is not freed
  95. * and null is returned. The returned value may be the same as ptr.
  96. */
  97. [noscript, notxpcom] voidPtr realloc(in voidPtr ptr,
  98. in size_t newSize);
  99. /**
  100. * Frees a block of memory. Null is a permissible value, in which case
  101. * nothing happens.
  102. *
  103. * @param ptr - the block of memory to free
  104. */
  105. [noscript, notxpcom] void free(in voidPtr ptr);
  106. /**
  107. * Attempts to shrink the heap.
  108. * @param immediate - if true, heap minimization will occur
  109. * immediately if the call was made on the main thread. If
  110. * false, the flush will be scheduled to happen when the app is
  111. * idle.
  112. * @return NS_ERROR_FAILURE if 'immediate' is set an the call
  113. * was not on the application's main thread.
  114. */
  115. void heapMinimize(in boolean immediate);
  116. /**
  117. * This predicate can be used to determine if we're in a low-memory
  118. * situation (what constitutes low-memory is platform dependent). This
  119. * can be used to trigger the memory pressure observers.
  120. */
  121. boolean isLowMemory();
  122. };