Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/salloc.cc File Reference

#include "salloc.h"
#include <stdio.h>
#include <lib/threads/mutex.h>

Include dependency graph for salloc.cc:

Include dependency graph

Go to the source code of this file.

Defines

#define malloc_usable_size(x)   1

Functions

void * _malloc (size_t size)
void * _realloc (void *ptr, size_t size)
void _free (void *ptr)
void LMallocSetLimit (size_t limit)
void LMallocGetUsage (struct LMallocUsage *dest)
void _LMallocPrintStats ()
void _LMallocExit ()
void * _LMalloc (size_t size)
void _LFree (void *ptr)
void * _LRealloc (void *ptr, size_t size)
void _AllocFailure (size_t size)
 Report allocation failure error and exit (internal).

void * LMalloc (size_t size)
 Allocate some memory (internal).

void * LFree (void *ptr)
 Free memory allocated via LMalloc (internal).

void * LRealloc (void *ptr, size_t size)
 Resize memory allocated via LMalloc (internal).


Variables

FastMutex mutex
LMallocUsage lmu


Define Documentation

#define malloc_usable_size  )     1
 

Definition at line 210 of file salloc.cc.

Referenced by _LFree(), _LMalloc(), and _LRealloc().


Function Documentation

void _AllocFailure size_t  size  ) 
 

Report allocation failure error and exit (internal).

Todo:
use an exception or portable error reporting mechanisms.

Definition at line 435 of file salloc.cc.

References _LMallocExit().

Referenced by LMalloc(), and LRealloc().

void _free void *  ptr  )  [inline]
 

Definition at line 31 of file salloc.cc.

References free.

Referenced by _LFree().

void _LFree void *  ptr  )  [inline, static]
 

Definition at line 278 of file salloc.cc.

References _free(), _LMallocExit(), LMallocUsage::curr_used, LMallocUsage::free_calls, lmu, malloc_usable_size, mutex, and LMallocUsage::used_chunks.

Referenced by LFree().

void* _LMalloc size_t  size  )  [inline, static]
 

Definition at line 214 of file salloc.cc.

References _LMallocExit(), _malloc(), LMallocUsage::alloc_limit, LMallocUsage::curr_used, LMallocUsage::limit_failures, lmu, LMallocUsage::malloc_calls, malloc_usable_size, LMallocUsage::max_used, LMallocUsage::max_used_chunks, mutex, LMallocUsage::real_failures, and LMallocUsage::used_chunks.

Referenced by LMalloc().

void _LMallocExit  )  [static]
 

Definition at line 93 of file salloc.cc.

References _LMallocPrintStats().

Referenced by _AllocFailure(), _LFree(), _LMalloc(), and _LRealloc().

void _LMallocPrintStats  )  [static]
 

Definition at line 68 of file salloc.cc.

References LMallocUsage::alloc_limit, LMallocUsage::curr_used, LMallocUsage::free_calls, LMALLOC_DEBUGGING, lmu, LMallocUsage::malloc_calls, LMallocUsage::max_used, LMallocUsage::max_used_chunks, LMallocUsage::realloc_calls, USE_MALLOC_USABLE_SIZE, and LMallocUsage::used_chunks.

Referenced by _LMallocExit().

void* _LRealloc void *  ptr,
size_t  size
[inline, static]
 

Definition at line 319 of file salloc.cc.

References _LMallocExit(), LMallocUsage::alloc_limit, LMallocUsage::curr_used, LFree(), LMallocUsage::limit_failures, LMalloc(), lmu, malloc_usable_size, LMallocUsage::max_used, mutex, LMallocUsage::real_failures, realloc, and LMallocUsage::realloc_calls.

Referenced by LRealloc().

void* _malloc size_t  size  )  [inline]
 

Definition at line 29 of file salloc.cc.

References malloc.

Referenced by _LMalloc().

void* _realloc void *  ptr,
size_t  size
[inline]
 

Definition at line 30 of file salloc.cc.

References realloc.

void* LFree void *  ptr  ) 
 

Free memory allocated via LMalloc (internal).

For internal use only.

These are the internal (de)allocation routines. Do not use these directly but use the below templates ALLOC, REALLOC, FREE instead.

Free memory as allocated by LMalloc or LRealloc. If called with a NULL pointer, nothing is done.

Parameters:
ptr pointer to the memory region as returned by LMalloc or LRealloc.
Returns:
always returns NULL.

Definition at line 453 of file salloc.cc.

References _LFree().

Referenced by _LRealloc(), FREE(), LRealloc(), operator delete(), and operator delete[]().

void* LMalloc size_t  size  ) 
 

Allocate some memory (internal).

For internal use only.

These are the internal (de)allocation routines. Do not use these directly but use the below templates ALLOC, REALLOC, FREE instead.

Parameters:
size desired size in bytes of the memory region
Returns:
always returns pointer to memory region; aborts using _AllocFailure on failure.
Return value is NULL if size=0.
See also:
ALLOC,REALLOC,FREE

Definition at line 443 of file salloc.cc.

References _AllocFailure(), and _LMalloc().

Referenced by _LRealloc(), ALLOC(), LRealloc(), operator new(), and operator new[]().

void LMallocGetUsage struct LMallocUsage dest  ) 
 

Get the LMallocUsage; pass a pointer where to store the values:

Definition at line 61 of file salloc.cc.

References lmu.

Referenced by main().

void LMallocSetLimit size_t  limit  ) 
 

Allocation limitation feature: Sets memory usage limit (0 -> no limit)

Definition at line 57 of file salloc.cc.

References LMallocUsage::alloc_limit, and lmu.

void* LRealloc void *  ptr,
size_t  size
 

Resize memory allocated via LMalloc (internal).

For internal use only.

These are the internal (de)allocation routines. Do not use these directly but use the below templates ALLOC, REALLOC, FREE instead.

Re-allocate memory allocated by LMalloc, i.e. change the size of the memory region. A pointer to the new memory region is returned.

  • If called with a NULL pointer, it behaves just as LMalloc(size)
  • If called with a size of 0, it it behaves exactly like LFree(ptr).
Parameters:
ptr pointer to the memory region as returned by LMalloc or LRealloc.
size new size in bytes of the memory region
Returns:
pointer to new memory region of specified size; aborts using _AllocFailure on failure.

Definition at line 461 of file salloc.cc.

References _AllocFailure(), _LRealloc(), LFree(), and LMalloc().

Referenced by REALLOC().


Variable Documentation

struct LMallocUsage lmu [static]
 

Initial value:

{
    INIT_FIELD(alloc_limit) 0,
    INIT_FIELD(curr_used) 0,
    INIT_FIELD(max_used) 0,
    INIT_FIELD(malloc_calls) 0,
    INIT_FIELD(realloc_calls) 0,
    INIT_FIELD(free_calls) 0,
    INIT_FIELD(used_chunks) 0,
    INIT_FIELD(max_used_chunks) 0,
    INIT_FIELD(real_failures) 0,
    INIT_FIELD(limit_failures) 0
}

Definition at line 42 of file salloc.cc.

Referenced by _LFree(), _LMalloc(), _LMallocPrintStats(), _LRealloc(), LMallocGetUsage(), and LMallocSetLimit().

FastMutex mutex [static]
 

Definition at line 40 of file salloc.cc.

Referenced by _LFree(), _LMalloc(), and _LRealloc().


Generated on Sat Feb 19 22:34:27 2005 for Ray by doxygen 1.3.5