nsMemory.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsXPCOM.h"
  6. #include "nsMemory.h"
  7. #include "nsIMemory.h"
  8. #include "nsXPCOMPrivate.h"
  9. #include "nsDebug.h"
  10. #include "nsISupportsUtils.h"
  11. #include "nsCOMPtr.h"
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // nsMemory static helper routines
  14. nsresult
  15. nsMemory::HeapMinimize(bool aImmediate)
  16. {
  17. nsCOMPtr<nsIMemory> mem;
  18. nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem));
  19. if (NS_WARN_IF(NS_FAILED(rv))) {
  20. return rv;
  21. }
  22. return mem->HeapMinimize(aImmediate);
  23. }
  24. void*
  25. nsMemory::Clone(const void* aPtr, size_t aSize)
  26. {
  27. void* newPtr = NS_Alloc(aSize);
  28. if (newPtr) {
  29. memcpy(newPtr, aPtr, aSize);
  30. }
  31. return newPtr;
  32. }
  33. nsIMemory*
  34. nsMemory::GetGlobalMemoryService()
  35. {
  36. nsIMemory* mem;
  37. nsresult rv = NS_GetMemoryManager(&mem);
  38. if (NS_FAILED(rv)) {
  39. return nullptr;
  40. }
  41. return mem;
  42. }
  43. //----------------------------------------------------------------------