Zen API
 All Classes Files Functions Variables Typedefs Macros Groups Pages
kDebugAlloc Class Reference

Description

Debug memory allocator; tracks allocations and can report leaks.

+ Inheritance diagram for kDebugAlloc:

Public Member Functions

kAlloc kAlloc_App ()
 Gets the allocator that should normally be used by applications to request memory. More...
 
kAlloc kAlloc_Fallback (kAlloc alloc)
 Returns the passed allocator, or if null, the App allocator. More...
 
kStatus kAlloc_Free (kAlloc alloc, void *mem)
 Frees a block of memory. More...
 
kStatus kAlloc_FreeRef (kAlloc alloc, void *mem)
 Frees a block of memory and sets the memory pointer to kNULL. More...
 
kStatus kAlloc_Get (kAlloc alloc, kSize size, void *mem)
 Allocates a block of memory. More...
 
kStatus kAlloc_GetZero (kAlloc alloc, kSize size, void *mem)
 Allocates a block of memory and zero-initializes the block. More...
 
kAlloc kAlloc_System ()
 Gets the system allocator. More...
 
kSize kDebugAlloc_Allocated (kDebugAlloc object)
 Returns the total amount of memory that has been allocated and not yet freed. More...
 
kStatus kDebugAlloc_Allocations (kDebugAlloc object, k64u since, kArrayList *history, kAlloc alloc)
 Gets a list of all outstanding memory allocations performed after the given checkpoint. More...
 
k64u kDebugAlloc_Checkpoint (kDebugAlloc object)
 Returns a memory checkpoint value, used in conjunction with allocation logging functions. More...
 
kStatus kDebugAlloc_Clear (kDebugAlloc object)
 Clears all outstanding allocations (resets allocator). More...
 
kStatus kDebugAlloc_Construct (kDebugAlloc *object, const kChar *name, kAlloc allocator)
 Constructs a new kDebugAlloc allocator. More...
 
kStatus kDebugAlloc_DetectLeakedAssemblyObjects (kDebugAlloc object, k64u since, kAssembly assembly)
 Makes note of outstanding allocations that appear to be objects associated with the specified assembly. More...
 
kStatus kDebugAlloc_DetectLeakedObjects (kDebugAlloc object, k64u since)
 Makes note of outstanding allocations that appear to be objects from any currently-loaded assembly. More...
 
kStatus kDebugAlloc_LogAllocations (kDebugAlloc object, k64u since)
 Logs all outstanding memory allocations performed after the given checkpoint (using kLogf). More...
 
kStatus kDebugAlloc_SetAllocListener (kDebugAlloc object, kCallbackFx function, kPointer receiver)
 Registers a user-defined function that is called whenever a memory allocation occurs. More...
 
kAlloc kObject_Alloc (kObject object)
 Gets the memory allocator associated with this object. More...
 
kStatus kObject_Clone (kObject *object, kObject source, kAlloc allocator)
 Constructs a new object by copying an existing object, including any aggregated child elements. More...
 
kStatus kObject_Destroy (kObject object)
 Destroys the object. More...
 
kStatus kObject_Dispose (kObject object)
 Destroys the object and any aggregated child elements. More...
 
kBool kObject_Equals (kObject object, kObject other)
 Determines whether the object is equal to another object. More...
 
kSize kObject_HashCode (kObject object)
 Gets a hash code representing the state of this object. More...
 
kBool kObject_Is (kObject object, kType type)
 Determines whether this object is an instance of the specified type. More...
 
kBool kObject_IsShared (kObject object)
 Reports whether the object is currently shared (reference count greater than one). More...
 
kStatus kObject_SetPool (kObject object, kObjectPool pool)
 Sets the object pool associated with this object. More...
 
kStatus kObject_Share (kObject object)
 Increments the reference count associated with this object. More...
 
kSize kObject_Size (kObject object)
 Estimates the memory consumed by this object, including any aggregated child elements. More...
 
kType kObject_Type (kObject object)
 Returns the type of the object. More...
 

Member Function Documentation

kAlloc kAlloc_App ( )
inherited

Gets the allocator that should normally be used by applications to request memory.

The App alloctor is typically implemented by layering additional allocators on the System allocator (e.g., kPoolAlloc, kDebugAlloc).

Returns
Application memory allocator.
kAlloc kAlloc_Fallback ( kAlloc  alloc)
inherited

Returns the passed allocator, or if null, the App allocator.

Parameters
allocAllocator.
Returns
Allocator.
kStatus kAlloc_Free ( kAlloc  alloc,
void *  mem 
)
inherited

Frees a block of memory.

Parameters
allocAllocator object.
memPointer to memory to be freed.
Returns
Operation status.
kStatus kAlloc_FreeRef ( kAlloc  alloc,
void *  mem 
)
inherited

Frees a block of memory and sets the memory pointer to kNULL.

Parameters
allocAllocator object.
memPointer to pointer to memory to be freed.
Returns
Operation status.
kStatus kAlloc_Get ( kAlloc  alloc,
kSize  size,
void *  mem 
)
inherited

Allocates a block of memory.

Parameters
allocAllocator object.
sizeSize of memory to be allocated.
memReceives pointer to allocated memory.
Returns
Operation status.
kStatus kAlloc_GetZero ( kAlloc  alloc,
kSize  size,
void *  mem 
)
inherited

Allocates a block of memory and zero-initializes the block.

Parameters
allocAllocator object.
sizeSize of memory to be allocated.
memReceives pointer to allocated memory.
Returns
Operation status.
kAlloc kAlloc_System ( )
inherited

Gets the system allocator.

The System allocator is a kUserAlloc instance that allocates directly from main system memory.

For most purposes, the App allocator should be prefered to the System allocator. Use of the System allocator may be appropriate when the additional layers provided by the App allocator are undesirable.

Returns
System memory allocator.
kSize kDebugAlloc_Allocated ( kDebugAlloc  object)

Returns the total amount of memory that has been allocated and not yet freed.

Parameters
objectMemory allocator.
Returns
Amount of allocated memory.
kStatus kDebugAlloc_Allocations ( kDebugAlloc  object,
k64u  since,
kArrayList history,
kAlloc  alloc 
)

Gets a list of all outstanding memory allocations performed after the given checkpoint.

Parameters
objectMemory allocator.
sinceMemory checkpoint (or zero for beginning).
historyReceives list of outstanding allocations.
allocAllocator for history list (or kNULL for default).
Returns
Operation status.
See also
kDebugAlloc_Checkpoint
k64u kDebugAlloc_Checkpoint ( kDebugAlloc  object)

Returns a memory checkpoint value, used in conjunction with allocation logging functions.

Parameters
objectMemory allocator.
Returns
Memory checkpoint value.
See also
kDebugAlloc_Allocations, kDebugAlloc_LogAllocations
kStatus kDebugAlloc_Clear ( kDebugAlloc  object)

Clears all outstanding allocations (resets allocator).

Parameters
objectMemory allocator.
Returns
Operation status.
kStatus kDebugAlloc_Construct ( kDebugAlloc object,
const kChar name,
kAlloc  allocator 
)

Constructs a new kDebugAlloc allocator.

Parameters
objectReceives the constructed kDebugAlloc object.
nameDescriptive name for this memory allocator.
allocatorMemory allocator to use for internal allocations (or kNULL for default).
Returns
Operation status.
kStatus kDebugAlloc_DetectLeakedAssemblyObjects ( kDebugAlloc  object,
k64u  since,
kAssembly  assembly 
)

Makes note of outstanding allocations that appear to be objects associated with the specified assembly.

This function records information about outstanding allocations that appear to be objects, for later use when logging leak information.

Parameters
objectMemory allocator.
sinceMemory checkpoint (or zero for beginning).
assemblyAssembly associated with objects.
Returns
Operation status.
See also
kDebugAlloc_LogAllocations, kDebugAlloc_DetectLeakedObjects
kStatus kDebugAlloc_DetectLeakedObjects ( kDebugAlloc  object,
k64u  since 
)

Makes note of outstanding allocations that appear to be objects from any currently-loaded assembly.

This function records information about outstanding allocations that appear to be objects, for later use when logging leak information.

Parameters
objectMemory allocator.
sinceMemory checkpoint (or zero for beginning).
Returns
Operation status.
See also
kDebugAlloc_LogAllocations, kDebugAlloc_DetectLeakedAssemblyObjects
kStatus kDebugAlloc_LogAllocations ( kDebugAlloc  object,
k64u  since 
)

Logs all outstanding memory allocations performed after the given checkpoint (using kLogf).

Parameters
objectMemory allocator.
sinceMemory checkpoint (or zero for beginning).
Returns
Operation status.
See also
kDebugAlloc_Checkpoint
kStatus kDebugAlloc_SetAllocListener ( kDebugAlloc  object,
kCallbackFx  function,
kPointer  receiver 
)

Registers a user-defined function that is called whenever a memory allocation occurs.

The args parameter of the callback will receive a pointer to a kDebugAllocation structure representing the memory allocation.

Parameters
objectMemory allocator.
functionCallback function.
receiverCallback receiver.
Returns
Operation status.
kAlloc kObject_Alloc ( kObject  object)
inherited

Gets the memory allocator associated with this object.

Most objects are constructed with an allocator, which is used to allocate the memory required by the object. Objects retain a reference to this allocator to enable further allocations and to free memory when the object is destroyed.

Parameters
objectObject.
Returns
Memory allocator.
See also
kAlloc, kObject_Alloc_
kStatus kObject_Clone ( kObject object,
kObject  source,
kAlloc  allocator 
)
inherited

Constructs a new object by copying an existing object, including any aggregated child elements.

If the source object is an object collection (e.g. kArrayList<kString>), any aggregated child objects are also cloned. In this case, the kObject_Dispose method can be used to free the cloned collection and its associated elements.

This method will fail if the source object (or an aggregated child element) does not support cloning.

Parameters
objectReceives the constructed object.
sourceSource object.
allocatorMemory allocator (or kNULL for default).
Returns
Operation status.
See also
kObject_Dispose
kStatus kObject_Destroy ( kObject  object)
inherited

Destroys the object.

The kObject_Destroy method destroys the object itself and any resources that are owned by the object. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters
objectObject (or kNULL).
Returns
Operation status.
See also
Object Destruction, Reference Counting
kStatus kObject_Dispose ( kObject  object)
inherited

Destroys the object and any aggregated child elements.

The kObject_Dispose method destroys the object itself, any resources that are owned by the object, and if the object represents a collection of objects, any child objects in the collection. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters
objectObject (or kNULL).
Returns
Operation status.
See also
Object Destruction, Reference Counting
kBool kObject_Equals ( kObject  object,
kObject  other 
)
inherited

Determines whether the object is equal to another object.

By default, objects are compared by reference; objects are considered equal if the given handles refer to the same object instance. However, some classes override the Equals method to provide a more meaningful comparison (e.g. kString).

Parameters
objectObject.
otherObject for comparison.
Returns
kTRUE if the objects are equal.
kSize kObject_HashCode ( kObject  object)
inherited

Gets a hash code representing the state of this object.

By default, objects return a hash code based on the object handle value. However, some classes override the HashCode method to provide a more useful hash (e.g. kString).

Parameters
objectObject.
Returns
Hash code.
kBool kObject_Is ( kObject  object,
kType  type 
)
inherited

Determines whether this object is an instance of the specified type.

This function compares the type of this object with the given type. An object is considered to be an instance of a given type if a) the type represents a class and this object inherits from (or instantiates) that class, or b) the type represents an interface and this object implements the interface.

Parameters
objectObject.
typeType.
Returns
kTRUE if the object is of the specified type; otherwise kFALSE.
See also
kObject_Is_, kType_Is
kBool kObject_IsShared ( kObject  object)
inherited

Reports whether the object is currently shared (reference count greater than one).

Objects are initialized with a reference count of one. The kObject_Share method can be used to increment the reference count. The kObject_Destroy and kObject_Dispose methods decrease the reference count, and when the reference count reaches zero, the object is actually destroyed/disposed.

This method can be used to determine if the reference count of an object is currently greater than one.

This method is thread-safe.

Parameters
objectObject.
Returns
kTRUE if the object is shared; kFALSE otherwise.
See also
Reference Counting, kObject_Share
kStatus kObject_SetPool ( kObject  object,
kObjectPool  pool 
)
inherited

Sets the object pool associated with this object.

Object pools can be used to implement custom lifecycle management. If an object has an assigned pool, then the kObjectPool_Reclaim method will be called just prior to destruction, to provide an opportunity for the object to be reclaimed.

Parameters
objectObject.
poolPool object (or kNULL to clear the pool assignment).
Returns
Operation status.
kStatus kObject_Share ( kObject  object)
inherited

Increments the reference count associated with this object.

This method is thread-safe.

Parameters
objectObject.
Returns
Operation status.
See also
reference-counting
kSize kObject_Size ( kObject  object)
inherited

Estimates the memory consumed by this object, including any aggregated child elements.

This method can be optionally overridden by kObject-derived classes to report the amount of memory consumed by an object. The default implementation reports only the size of the class instance (additional allocations performed by the class are excluded).

Parameters
objectObject.
Returns
Object size, in bytes.
kType kObject_Type ( kObject  object)
inherited

Returns the type of the object.

Each object is an instance of a specific class type. The type handle returned by this function can be used to learn about the class.

Parameters
objectObject.
Returns
Type.
See also
kType, kObject_Type_

The documentation for this class was generated from the following file: