2001-12-07 22:54:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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
|
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
NS_COM_GLUE nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsMemory::HeapMinimize(bool aImmediate)
|
2001-12-07 22:54:16 +03:00
|
|
|
{
|
2004-11-12 22:26:37 +03:00
|
|
|
nsCOMPtr<nsIMemory> mem;
|
|
|
|
nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem));
|
2013-11-20 01:27:37 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2001-12-07 22:54:16 +03:00
|
|
|
|
2004-11-12 22:26:37 +03:00
|
|
|
return mem->HeapMinimize(aImmediate);
|
2001-12-07 22:54:16 +03:00
|
|
|
}
|
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
NS_COM_GLUE void*
|
2012-08-09 11:10:11 +04:00
|
|
|
nsMemory::Clone(const void* ptr, size_t size)
|
2001-12-07 22:54:16 +03:00
|
|
|
{
|
2004-11-12 22:26:37 +03:00
|
|
|
void* newPtr = NS_Alloc(size);
|
2001-12-07 22:54:16 +03:00
|
|
|
if (newPtr)
|
|
|
|
memcpy(newPtr, ptr, size);
|
|
|
|
return newPtr;
|
|
|
|
}
|
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
NS_COM_GLUE nsIMemory*
|
2001-12-07 22:54:16 +03:00
|
|
|
nsMemory::GetGlobalMemoryService()
|
|
|
|
{
|
2004-11-12 22:26:37 +03:00
|
|
|
nsIMemory* mem;
|
|
|
|
nsresult rv = NS_GetMemoryManager(&mem);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (NS_FAILED(rv)) return nullptr;
|
2001-12-07 22:54:16 +03:00
|
|
|
|
2004-11-12 22:26:37 +03:00
|
|
|
return mem;
|
2001-12-07 22:54:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|