Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsMemoryImpl.cpp File Reference
#include "nsXPCOM.h"
#include "nsMemoryImpl.h"
#include "nsIEventQueueService.h"
#include "nsIObserverService.h"
#include "nsIRunnable.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsIThread.h"
#include "prmem.h"
#include "plevent.h"
#include "nsAlgorithm.h"
#include "nsAutoLock.h"
#include "nsCOMPtr.h"
#include "nsString.h"

Go to the source code of this file.

Defines

#define MALLOC1(s)   PR_Malloc(s)
#define REALLOC1(p, s)   PR_Realloc(p, s)

Functions

NS_EXPORT voidNS_Alloc (PRSize size)
 Allocates a block of memory of a particular size.
NS_EXPORT voidNS_Realloc (void *ptr, PRSize size)
 Reallocates a block of memory to a new size.
NS_EXPORT void NS_Free (void *ptr)
 Frees a block of memory.
nsresult NS_GetMemoryManager (nsIMemory **result)
 Public Method to access to the memory manager.

Variables

static nsMemoryImpl sGlobalMemory

Define Documentation

#define MALLOC1 (   s)    PR_Malloc(s)

Definition at line 109 of file nsMemoryImpl.cpp.

#define REALLOC1 (   p,
  s 
)    PR_Realloc(p, s)

Definition at line 110 of file nsMemoryImpl.cpp.


Function Documentation

Allocates a block of memory of a particular size.

If the memory cannot be allocated (because of an out-of-memory condition), null is returned.

FROZEN

Parameters:
sizeThe size of the block to allocate
Returns:
The block of memory
Note:
This function is thread-safe.

Definition at line 333 of file nsMemoryImpl.cpp.

{
    NS_ASSERTION(size, "NS_Alloc of size 0");

    void* result = MALLOC1(size);
    if (! result) {
        // Request an asynchronous flush
        sGlobalMemory.FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE);
    }
    return result;
}

Here is the caller graph for this function:

NS_EXPORT void NS_Free ( void ptr)

Frees a block of memory.

Null is a permissible value, in which case no action is taken.

FROZEN

Parameters:
ptrThe block of memory to free. This block must originally have been allocated by NS_Alloc or NS_Realloc
Note:
This function is thread-safe.

Definition at line 358 of file nsMemoryImpl.cpp.

{
    PR_Free(ptr);
}

Here is the caller graph for this function:

Public Method to access to the memory manager.

See nsIMemory

FROZEN

Parameters:
resultInterface pointer to the memory manager
Returns:
NS_OK for success; other error codes indicate a failure during initialisation.

Definition at line 475 of file nsMemoryImpl.cpp.

{
    return sGlobalMemory.QueryInterface(NS_GET_IID(nsIMemory), (void**) result);
}

Here is the caller graph for this function:

NS_EXPORT void* NS_Realloc ( void ptr,
PRSize  size 
)

Reallocates a block of memory to a new size.

FROZEN

Parameters:
ptrThe block of memory to reallocate. This block must originally have been allocated by NS_Alloc or NS_Realloc
sizeThe new size. If 0, frees the block like NS_Free
Returns:
The reallocated block of memory
Note:
This function is thread-safe.

If ptr is null, this function behaves like NS_Alloc. If s is the size of the block to which ptr points, the first min(s, size) bytes of ptr's block are copied to the new block. If the allocation succeeds, ptr is freed and a pointer to the new block is returned. If the allocation fails, ptr is not freed and null is returned. The returned value may be the same as ptr.

Definition at line 346 of file nsMemoryImpl.cpp.

{
    NS_ASSERTION(size, "NS_Realloc of size 0");
    void* result = REALLOC1(ptr, size);
    if (! result) {
        // Request an asynchronous flush
        sGlobalMemory.FlushMemory(NS_LITERAL_STRING("alloc-failure").get(), PR_FALSE);
    }
    return result;
}

Variable Documentation

Definition at line 154 of file nsMemoryImpl.cpp.