Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

Memory Allocation
[D-BUS message system public API]

dbus_malloc(), dbus_free(), etc. More...

Defines

#define dbus_new(type, count)   ((type*)dbus_malloc (sizeof (type) * (count)));
 Safe macro for using dbus_malloc().
#define dbus_new0(type, count)   ((type*)dbus_malloc0 (sizeof (type) * (count)));
 Safe macro for using dbus_malloc0().

Typedefs

typedef void(* DBusFreeFunction )(void *memory)
 The type of a function which frees a block of memory.

Functions

void * dbus_malloc (size_t bytes)
 Allocates the given number of bytes, as with standard malloc().
void * dbus_malloc0 (size_t bytes)
 Allocates the given number of bytes, as with standard malloc(), but all bytes are initialized to zero as with calloc().
void * dbus_realloc (void *memory, size_t bytes)
 Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void dbus_free (void *memory)
 Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
void dbus_free_string_array (char **str_array)
 Frees a NULL-terminated array of strings.
void dbus_shutdown (void)
 The D-BUS library keeps some internal global variables, for example to cache the username of the current process.

Detailed Description

dbus_malloc(), dbus_free(), etc.

Functions and macros related to allocating and releasing blocks of memory.


Define Documentation

#define dbus_new type,
count   )     ((type*)dbus_malloc (sizeof (type) * (count)));
 

Safe macro for using dbus_malloc().

Accepts the type to allocate and the number of type instances to allocate as arguments, and returns a memory block cast to the desired type, instead of as a void*.

Parameters:
type type name to allocate
count number of instances in the allocated array
Returns:
the new memory block or NULL on failure

Definition at line 41 of file dbus-memory.h.

Referenced by _dbus_counter_new(), _dbus_demarshal_string_array(), _dbus_register_shutdown_func(), _dbus_user_database_get_groups(), and dbus_parse_address().

#define dbus_new0 type,
count   )     ((type*)dbus_malloc0 (sizeof (type) * (count)));
 

Safe macro for using dbus_malloc0().

Accepts the type to allocate and the number of type instances to allocate as arguments, and returns a memory block cast to the desired type, instead of as a void*. The allocated array is initialized to all-bits-zero.

Parameters:
type type name to allocate
count number of instances in the allocated array
Returns:
the new memory block or NULL on failure

Definition at line 42 of file dbus-memory.h.

Referenced by _dbus_connection_new_for_transport(), _dbus_decompose_path(), _dbus_directory_open(), _dbus_dup_string_array(), _dbus_hash_table_new(), _dbus_mem_pool_new(), _dbus_message_loader_new(), _dbus_object_tree_new(), _dbus_pending_call_new(), _dbus_server_new_for_fd(), _dbus_timeout_list_new(), _dbus_timeout_new(), _dbus_transport_new_for_fd(), _dbus_user_database_new(), _dbus_watch_list_new(), _dbus_watch_new(), dbus_connection_add_filter(), dbus_message_copy(), and dbus_parse_address().


Typedef Documentation

DBusFreeFunction
 

The type of a function which frees a block of memory.

Parameters:
memory the memory to free

Definition at line 46 of file dbus-memory.h.

Referenced by _dbus_babysitter_set_watch_functions(), _dbus_connection_new_for_transport(), _dbus_data_slot_list_set(), _dbus_hash_table_new(), _dbus_timeout_list_set_functions(), _dbus_timeout_new(), _dbus_transport_set_unix_user_function(), _dbus_watch_list_set_functions(), _dbus_watch_new(), _dbus_watch_set_handler(), dbus_connection_add_filter(), dbus_connection_set_data(), dbus_connection_set_dispatch_status_function(), dbus_connection_set_timeout_functions(), dbus_connection_set_unix_user_function(), dbus_connection_set_wakeup_main_function(), dbus_connection_set_watch_functions(), dbus_connection_setup_with_g_main(), dbus_message_set_data(), dbus_pending_call_set_data(), dbus_pending_call_set_notify(), dbus_server_set_data(), dbus_server_set_new_connection_function(), dbus_server_set_timeout_functions(), dbus_server_set_watch_functions(), dbus_server_setup_with_g_main(), dbus_timeout_set_data(), and dbus_watch_set_data().


Function Documentation

void dbus_free void *  memory  ) 
 

Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().

If passed NULL, does nothing.

Parameters:
memory block to be freed

Definition at line 605 of file dbus-memory.c.

References _dbus_assert.

Referenced by _dbus_auth_unref(), _dbus_babysitter_unref(), _dbus_connection_new_for_transport(), _dbus_counter_unref(), _dbus_data_slot_allocator_free(), _dbus_data_slot_list_free(), _dbus_demarshal_byte_array(), _dbus_demarshal_string_array(), _dbus_directory_close(), _dbus_group_info_free(), _dbus_hash_table_new(), _dbus_hash_table_unref(), _dbus_keyring_unref(), _dbus_mem_pool_dealloc(), _dbus_mem_pool_free(), _dbus_message_loader_new(), _dbus_message_loader_unref(), _dbus_object_tree_new(), _dbus_object_tree_unref(), _dbus_pending_call_new(), _dbus_server_finalize_base(), _dbus_server_init_base(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_fd(), _dbus_string_free(), _dbus_timeout_list_free(), _dbus_timeout_unref(), _dbus_transport_finalize_base(), _dbus_transport_new_for_fd(), _dbus_user_database_unref(), _dbus_user_info_free(), _dbus_watch_list_free(), _dbus_watch_unref(), dbus_address_entries_free(), dbus_connection_free_preallocated_send(), dbus_error_free(), dbus_free_string_array(), dbus_g_proxy_new_for_service_owner(), dbus_message_copy(), dbus_message_iter_get_custom(), dbus_message_unref(), dbus_parse_address(), dbus_pending_call_unref(), dbus_realloc(), dbus_set_error_from_message(), and dbus_shutdown().

void dbus_free_string_array char **  str_array  ) 
 

Frees a NULL-terminated array of strings.

If passed NULL, does nothing.

Parameters:
str_array the array to be freed

Definition at line 643 of file dbus-memory.c.

References dbus_free().

Referenced by _dbus_auth_set_mechanisms(), _dbus_auth_unref(), _dbus_decompose_path(), _dbus_dup_string_array(), _dbus_object_tree_dispatch_and_unlock(), _dbus_server_finalize_base(), dbus_connection_list_registered(), dbus_connection_register_fallback(), dbus_connection_register_object_path(), dbus_connection_unregister_object_path(), and dbus_server_set_auth_mechanisms().

void* dbus_malloc size_t  bytes  ) 
 

Allocates the given number of bytes, as with standard malloc().

Guaranteed to return NULL if bytes is zero on all platforms. Returns NULL if the allocation fails. The memory must be released with dbus_free().

Parameters:
bytes number of bytes to allocate
Returns:
allocated memory, or NULL if the allocation fails.

Definition at line 430 of file dbus-memory.c.

Referenced by _dbus_demarshal_byte_array(), _dbus_demarshal_string(), _dbus_mem_pool_alloc(), _dbus_memdup(), _dbus_strdup(), _dbus_string_copy_data(), and _dbus_string_init_preallocated().

void* dbus_malloc0 size_t  bytes  ) 
 

Allocates the given number of bytes, as with standard malloc(), but all bytes are initialized to zero as with calloc().

Guaranteed to return NULL if bytes is zero on all platforms. Returns NULL if the allocation fails. The memory must be released with dbus_free().

Parameters:
bytes number of bytes to allocate
Returns:
allocated memory, or NULL if the allocation fails.

Definition at line 481 of file dbus-memory.c.

Referenced by _dbus_mem_pool_alloc().

void* dbus_realloc void *  memory,
size_t  bytes
 

Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().

Guaranteed to free the memory and return NULL if bytes is zero on all platforms. Returns NULL if the resize fails. If the resize fails, the memory is not freed.

Parameters:
memory block to be resized
bytes new size of the memory block
Returns:
allocated memory, or NULL if the resize fails.

Definition at line 532 of file dbus-memory.c.

References dbus_free(), dbus_uint32_t, and NULL.

Referenced by _dbus_data_slot_allocator_alloc(), _dbus_data_slot_list_set(), and _dbus_demarshal_string_array().

void dbus_shutdown void   ) 
 

The D-BUS library keeps some internal global variables, for example to cache the username of the current process.

This function is used to free these global variables. It is really useful only for leak-checking cleanliness and the like. WARNING: this function is NOT thread safe, it must be called while NO other threads are using D-BUS. You cannot continue using D-BUS after calling this function, as it does things like free global mutexes created by dbus_threads_init(). To use a D-BUS function after calling dbus_shutdown(), you have to start over from scratch, e.g. calling dbus_threads_init() again.

Definition at line 749 of file dbus-memory.c.

References _dbus_current_generation, ShutdownClosure::data, dbus_free(), ShutdownClosure::func, ShutdownClosure::next, and ShutdownClosure.


Generated on Sat Sep 25 19:17:14 2004 for D-BUS by  doxygen 1.3.8-20040913