2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-12-07 22:54:16 +03:00
|
|
|
|
2002-03-22 02:43:21 +03:00
|
|
|
#include "nsXPCOM.h"
|
2001-12-07 22:54:16 +03:00
|
|
|
#include "nsMemory.h"
|
2013-08-13 01:44:56 +04:00
|
|
|
#include "nsIMemory.h"
|
2001-12-07 22:54:16 +03:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2004-10-25 23:34:45 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2004-11-12 22:26:37 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-12-07 22:54:16 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsMemory static helper routines
|
|
|
|
|
2014-08-28 02:47:27 +04:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsMemory::HeapMinimize(bool aImmediate)
|
2001-12-07 22:54:16 +03:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
nsCOMPtr<nsIMemory> mem;
|
|
|
|
nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2001-12-07 22:54:16 +03:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
return mem->HeapMinimize(aImmediate);
|
2001-12-07 22:54:16 +03:00
|
|
|
}
|
|
|
|
|
2014-08-28 02:47:27 +04:00
|
|
|
void*
|
2014-06-27 05:35:39 +04:00
|
|
|
nsMemory::Clone(const void* aPtr, size_t aSize)
|
2001-12-07 22:54:16 +03:00
|
|
|
{
|
2017-10-12 05:08:44 +03:00
|
|
|
void* newPtr = moz_xmalloc(aSize);
|
2014-06-27 05:35:39 +04:00
|
|
|
if (newPtr) {
|
|
|
|
memcpy(newPtr, aPtr, aSize);
|
|
|
|
}
|
|
|
|
return newPtr;
|
2001-12-07 22:54:16 +03:00
|
|
|
}
|
|
|
|
|
2014-08-28 02:47:27 +04:00
|
|
|
nsIMemory*
|
2001-12-07 22:54:16 +03:00
|
|
|
nsMemory::GetGlobalMemoryService()
|
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
nsIMemory* mem;
|
|
|
|
nsresult rv = NS_GetMemoryManager(&mem);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mem;
|
2001-12-07 22:54:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|