Class

PurpleMemoryPool

Description [src]

class Purple.MemoryPool : GObject.Object {
  /* No available fields */
}

A PurpleMemoryPool allows allocating many small objects within a single memory range and releasing them all at once using a single call. This prevents memory fragmentation and improves performance when used properly. Its purpose is to act as an internal storage for other object private structures, like tree nodes, string chunks, list elements.

Current implementation is not optimized for releasing individual objects, so it may be extremely inefficient, when misused. On every memory allocation, it checks if there is enough space in current block. If there is not enough room here, it creates another block of memory. On pool destruction or calling

purple_memory_pool_cleanup, the whole block chain will be freed, using only

one #g_free call for every block.

Ancestors

Constructors

purple_memory_pool_new

Creates a new memory pool.

Instance methods

purple_memory_pool_alloc

Allocates an aligned memory block within a pool.

purple_memory_pool_alloc0

Allocates an aligned memory block within a pool and sets its contents to zeros.

purple_memory_pool_cleanup

Marks all memory allocated within a memory pool as not used. It may free resources, but don’t have to.

purple_memory_pool_free

Frees a memory allocated within a memory pool. This can be a no-op in certain implementations. Thus, it don’t need to be called in every case. Thus, the freed memory is wasted until you call #purple_memory_pool_cleanup or destroy the pool.

purple_memory_pool_set_block_size

Sets new default block size for a memory pool. You might want to call this before any allocation, to have it applied to the every created block.

purple_memory_pool_strdup

Duplicates a string using a memory allocated within a memory pool. If str is NULL, it returns NULL. The returned string should be freed with g_free() when no longer needed.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

Purple.MemoryPool:block-size
No description available.

Signals

Signals inherited from GObject (1)
GObject.Object::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct PurpleMemoryPoolClass {
  gpointer (* palloc) (
    PurpleMemoryPool* pool,
    gsize size,
    guint alignment
  );
  gpointer (* pfree) (
    PurpleMemoryPool* pool,
    gpointer mem
  );
  void (* cleanup) (
    PurpleMemoryPool* pool
  );
  void (* purple_reserved1) (
void
  );
  void (* purple_reserved2) (
void
  );
  void (* purple_reserved3) (
void
  );
  void (* purple_reserved4) (
void
  );
  
}

Base class for PurpleMemoryPool objects.

Class members
palloc
gpointer (* palloc) (
    PurpleMemoryPool* pool,
    gsize size,
    guint alignment
  )
  No description available.
pfree
gpointer (* pfree) (
    PurpleMemoryPool* pool,
    gpointer mem
  )
  No description available.
cleanup
void (* cleanup) (
    PurpleMemoryPool* pool
  )
  No description available.
purple_reserved1
void (* purple_reserved1) (
void
  )
  No description available.
purple_reserved2
void (* purple_reserved2) (
void
  )
  No description available.
purple_reserved3
void (* purple_reserved3) (
void
  )
  No description available.
purple_reserved4
void (* purple_reserved4) (
void
  )
  No description available.

Virtual methods

Purple.MemoryPoolClass.cleanup

Marks all memory allocated within a memory pool as not used. It may free resources, but don’t have to.

Purple.MemoryPoolClass.palloc
No description available.
Purple.MemoryPoolClass.pfree
No description available.