2001-12-07 19:54:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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 19:54:16 +00:00
|
|
|
|
2002-03-21 23:43:21 +00:00
|
|
|
#include "nsXPCOM.h"
|
2001-12-07 19:54:16 +00:00
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsXPCOMPrivate.h"
|
2004-10-25 19:34:45 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2004-11-12 19:26:37 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-12-07 19:54:16 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsMemory static helper routines
|
|
|
|
|
2004-10-29 19:43:51 +00:00
|
|
|
NS_COM_GLUE nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
nsMemory::HeapMinimize(bool aImmediate)
|
2001-12-07 19:54:16 +00:00
|
|
|
{
|
2004-11-12 19:26:37 +00:00
|
|
|
nsCOMPtr<nsIMemory> mem;
|
|
|
|
nsresult rv = NS_GetMemoryManager(getter_AddRefs(mem));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-12-07 19:54:16 +00:00
|
|
|
|
2004-11-12 19:26:37 +00:00
|
|
|
return mem->HeapMinimize(aImmediate);
|
2001-12-07 19:54:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-29 19:43:51 +00:00
|
|
|
NS_COM_GLUE void*
|
2001-12-07 19:54:16 +00:00
|
|
|
nsMemory::Clone(const void* ptr, PRSize size)
|
|
|
|
{
|
2004-11-12 19:26:37 +00:00
|
|
|
void* newPtr = NS_Alloc(size);
|
2001-12-07 19:54:16 +00:00
|
|
|
if (newPtr)
|
|
|
|
memcpy(newPtr, ptr, size);
|
|
|
|
return newPtr;
|
|
|
|
}
|
|
|
|
|
2004-10-29 19:43:51 +00:00
|
|
|
NS_COM_GLUE nsIMemory*
|
2001-12-07 19:54:16 +00:00
|
|
|
nsMemory::GetGlobalMemoryService()
|
|
|
|
{
|
2004-11-12 19:26:37 +00:00
|
|
|
nsIMemory* mem;
|
|
|
|
nsresult rv = NS_GetMemoryManager(&mem);
|
2012-07-30 14:20:58 +00:00
|
|
|
if (NS_FAILED(rv)) return nullptr;
|
2001-12-07 19:54:16 +00:00
|
|
|
|
2004-11-12 19:26:37 +00:00
|
|
|
return mem;
|
2001-12-07 19:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|