|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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 |
|
6 #include "nsXPCOM.h" |
|
7 #include "nsMemory.h" |
|
8 #include "nsIMemory.h" |
|
9 #include "nsXPCOMPrivate.h" |
|
10 #include "nsDebug.h" |
|
11 #include "nsISupportsUtils.h" |
|
12 #include "nsCOMPtr.h" |
|
13 |
|
14 //////////////////////////////////////////////////////////////////////////////// |
|
15 // nsMemory static helper routines |
|
16 |
|
17 NS_COM_GLUE nsresult |
|
18 nsMemory::HeapMinimize(bool aImmediate) |
|
19 { |
|
20 nsCOMPtr<nsIMemory> mem; |
|
21 nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem)); |
|
22 if (NS_WARN_IF(NS_FAILED(rv))) |
|
23 return rv; |
|
24 |
|
25 return mem->HeapMinimize(aImmediate); |
|
26 } |
|
27 |
|
28 NS_COM_GLUE void* |
|
29 nsMemory::Clone(const void* ptr, size_t size) |
|
30 { |
|
31 void* newPtr = NS_Alloc(size); |
|
32 if (newPtr) |
|
33 memcpy(newPtr, ptr, size); |
|
34 return newPtr; |
|
35 } |
|
36 |
|
37 NS_COM_GLUE nsIMemory* |
|
38 nsMemory::GetGlobalMemoryService() |
|
39 { |
|
40 nsIMemory* mem; |
|
41 nsresult rv = NS_GetMemoryManager(&mem); |
|
42 if (NS_FAILED(rv)) return nullptr; |
|
43 |
|
44 return mem; |
|
45 } |
|
46 |
|
47 //---------------------------------------------------------------------- |
|
48 |