1999-01-27 02:02:22 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-01-27 02:02:22 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-01-27 02:02:22 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-01-27 02:02:22 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-01-27 02:02:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsIAllocator_h___
|
|
|
|
#define nsIAllocator_h___
|
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlike IMalloc, this interface returns nsresults and doesn't
|
|
|
|
* implement the problematic GetSize and DidAlloc routines.
|
|
|
|
*/
|
|
|
|
|
1999-02-26 04:04:13 +00:00
|
|
|
#define NS_IALLOCATOR_IID \
|
|
|
|
{ /* 56def700-b1b9-11d2-8177-006008119d7a */ \
|
|
|
|
0x56def700, \
|
|
|
|
0xb1b9, \
|
|
|
|
0x11d2, \
|
|
|
|
{0x81, 0x77, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
|
|
|
}
|
1999-05-27 22:41:23 +00:00
|
|
|
#define NS_ALLOCATOR_PROGID "component://netscape/allocator"
|
|
|
|
#define NS_ALLOCATOR_CLASSNAME "Allocator"
|
1999-02-26 04:04:13 +00:00
|
|
|
|
1999-01-27 02:02:22 +00:00
|
|
|
class nsIAllocator : public nsISupports {
|
|
|
|
public:
|
1999-03-03 19:48:57 +00:00
|
|
|
static const nsIID& GetIID() { static nsIID iid = NS_IALLOCATOR_IID; return iid; }
|
1999-02-26 04:04:13 +00:00
|
|
|
|
1999-01-27 02:02:22 +00:00
|
|
|
/**
|
|
|
|
* Allocates a block of memory of a particular size.
|
|
|
|
*
|
|
|
|
* @param size - the size of the block to allocate
|
|
|
|
* @result the block of memory
|
|
|
|
*/
|
|
|
|
NS_IMETHOD_(void*) Alloc(PRUint32 size) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reallocates a block of memory to a new size.
|
|
|
|
*
|
|
|
|
* @param ptr - the block of memory to reallocate
|
|
|
|
* @param size - the new size
|
|
|
|
* @result the rellocated block of memory
|
|
|
|
*/
|
1999-05-07 06:22:11 +00:00
|
|
|
NS_IMETHOD_(void*) Realloc(void* ptr, PRUint32 size) = 0;
|
1999-01-27 02:02:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Frees a block of memory.
|
|
|
|
*
|
|
|
|
* @param ptr - the block of memory to free
|
1999-04-30 22:54:28 +00:00
|
|
|
* @param size - the size of the block to be freed. If -1 (the default),
|
|
|
|
* the implementation must be able to determine the block size by
|
|
|
|
* examining the block pointer.
|
1999-01-27 02:02:22 +00:00
|
|
|
*/
|
1999-05-07 06:22:11 +00:00
|
|
|
NS_IMETHOD Free(void* ptr) = 0;
|
1999-01-27 02:02:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to shrink the heap.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD HeapMinimize(void) = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// To get the global memory manager service:
|
|
|
|
#define NS_ALLOCATOR_CID \
|
|
|
|
{ /* aafe6770-b1bb-11d2-8177-006008119d7a */ \
|
|
|
|
0xaafe6770, \
|
|
|
|
0xb1bb, \
|
|
|
|
0x11d2, \
|
|
|
|
{0x81, 0x77, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
|
|
|
}
|
|
|
|
|
1999-04-01 23:12:49 +00:00
|
|
|
/*
|
|
|
|
* Public shortcuts to the shared allocator's methods
|
|
|
|
*/
|
|
|
|
|
1999-04-02 06:17:28 +00:00
|
|
|
class nsAllocator
|
1999-04-01 23:12:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static NS_EXPORT void* Alloc(PRUint32 size);
|
|
|
|
static NS_EXPORT void* Realloc(void* ptr, PRUint32 size);
|
|
|
|
static NS_EXPORT void Free(void* ptr);
|
|
|
|
static NS_EXPORT void HeapMinimize();
|
|
|
|
static NS_EXPORT void* Clone(const void* ptr, PRUint32 size);
|
1999-08-10 19:54:17 +00:00
|
|
|
static NS_EXPORT nsIAllocator* GetGlobalAllocator();
|
1999-04-01 23:12:49 +00:00
|
|
|
private:
|
1999-04-02 06:17:28 +00:00
|
|
|
nsAllocator(); // not implemented
|
1999-04-01 23:12:49 +00:00
|
|
|
static PRBool EnsureAllocator() {return mAllocator || FetchAllocator();}
|
|
|
|
static PRBool FetchAllocator();
|
|
|
|
static nsIAllocator* mAllocator;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-01-27 02:02:22 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif /* nsIAllocator_h___ */
|