glib.Memory.Memory Class Reference

List of all members.

Detailed Description

Description These functions provide support for allocating and freeing memory.

Note If any call to allocate memory fails, the application is terminated. This also means that there is no need to check if the call succeeded.


Static Public Member Functions

static void * malloc (uint nBytes)
 Allocates n_bytes bytes of memory.
static void * malloc0 (uint nBytes)
 Allocates n_bytes bytes of memory, initialized to 0's.
static void * realloc (void *mem, uint nBytes)
 Reallocates the memory pointed to by mem, so that it now has space for n_bytes bytes of memory.
static void * tryMalloc (uint nBytes)
 Attempts to allocate n_bytes, and returns NULL on failure.
static void * tryMalloc0 (uint nBytes)
 Attempts to allocate n_bytes, initialized to 0's, and returns NULL on failure.
static void * tryRealloc (void *mem, uint nBytes)
 Attempts to realloc mem to a new size, n_bytes, and returns NULL on failure.
static void free (void *mem)
 Frees the memory pointed to by mem.
static void * memdup (void *mem, uint byteSize)
 Allocates byte_size bytes of memory, and copies byte_size bytes into it from mem.
static void memSetVtable (GMemVTable *vtable)
 Sets the GMemVTable to use for memory allocation.
static int memIsSystemMalloc ()
 Checks whether the allocator used by g_malloc() is the system's malloc implementation.
static void memProfile ()
 Outputs a summary of memory usage.


Member Function Documentation

static void glib.Memory.Memory.free ( void *  mem  )  [static]

Frees the memory pointed to by mem.

If mem is NULL it simply returns. mem: the memory to free.

static void* glib.Memory.Memory.malloc ( uint  nBytes  )  [static]

Allocates n_bytes bytes of memory.

If n_bytes is 0 it returns NULL. n_bytes: the number of bytes to allocate. Returns: a pointer to the allocated memory.

static void* glib.Memory.Memory.malloc0 ( uint  nBytes  )  [static]

Allocates n_bytes bytes of memory, initialized to 0's.

If n_bytes is 0 it returns NULL. n_bytes: the number of bytes to allocate. Returns: a pointer to the allocated memory.

static void* glib.Memory.Memory.memdup ( void *  mem,
uint  byteSize 
) [static]

Allocates byte_size bytes of memory, and copies byte_size bytes into it from mem.

If mem is NULL it returns NULL. mem: the memory to copy. byte_size: the number of bytes to copy. Returns: a pointer to the newly-allocated copy of the memory, or NULL if mem is NULL.

static int glib.Memory.Memory.memIsSystemMalloc (  )  [static]

Checks whether the allocator used by g_malloc() is the system's malloc implementation.

If it returns TRUE memory allocated with malloc() can be used interchangeable with memory allocated using g_malloc(). This function is useful for avoiding an extra copy of allocated memory returned by a non-GLib-based API. A different allocator can be set using g_mem_set_vtable(). Returns: if TRUE, malloc() and g_malloc() can be mixed.

static void glib.Memory.Memory.memProfile (  )  [static]

Outputs a summary of memory usage.

It outputs the frequency of allocations of different sizes, the total number of bytes which have been allocated, the total number of bytes which have been freed, and the difference between the previous two values, i.e. the number of bytes still in use. Note that this function will not output anything unless you have previously installed the glib_mem_profiler_table with g_mem_set_vtable().

static void glib.Memory.Memory.memSetVtable ( GMemVTable vtable  )  [static]

Sets the GMemVTable to use for memory allocation.

You can use this to provide custom memory allocation routines. This function must be called before using any other GLib functions. The vtable only needs to provide malloc(), realloc(), and free() functions; GLib can provide default implementations of the others. The malloc() and realloc() implementations should return NULL on failure, GLib will handle error-checking for you. vtable is copied, so need not persist after this function has been called. vtable: table of memory allocation routines.

static void* glib.Memory.Memory.realloc ( void *  mem,
uint  nBytes 
) [static]

Reallocates the memory pointed to by mem, so that it now has space for n_bytes bytes of memory.

It returns the new address of the memory, which may have been moved. mem may be NULL, in which case it's considered to have zero-length. n_bytes may be 0, in which case NULL will be returned. mem: the memory to reallocate. n_bytes: new size of the memory in bytes. Returns: the new address of the allocated memory.

static void* glib.Memory.Memory.tryMalloc ( uint  nBytes  )  [static]

Attempts to allocate n_bytes, and returns NULL on failure.

Contrast with g_malloc(), which aborts the program on failure. n_bytes: number of bytes to allocate. Returns: the allocated memory, or NULL.

static void* glib.Memory.Memory.tryMalloc0 ( uint  nBytes  )  [static]

Attempts to allocate n_bytes, initialized to 0's, and returns NULL on failure.

Contrast with g_malloc0(), which aborts the program on failure. n_bytes: number of bytes to allocate. Returns: the allocated memory, or NULL. Since 2.8

static void* glib.Memory.Memory.tryRealloc ( void *  mem,
uint  nBytes 
) [static]

Attempts to realloc mem to a new size, n_bytes, and returns NULL on failure.

Contrast with g_realloc(), which aborts the program on failure. If mem is NULL, behaves the same as g_try_malloc(). mem: previously-allocated memory, or NULL. n_bytes: number of bytes to allocate. Returns: the allocated memory, or NULL.


SourceForge.net Logo DSource.org Logo digitalmars.com Logo