Defines interfaceable object which offers memory manager functionality. Implemented by mm_impl_t.
MemoryManager-Object | Defines interfaceable object which offers memory manager functionality. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of MemoryManager-Object. |
C-kern/ | Implements unittest MemoryManager-Object impl. |
Types | |
struct mm_t | Export mm_t. |
struct mm_it | Export interface mm_it. |
Functions | |
test | |
unittest_memory_mm_mm | Test mm_it functionality. |
mm_t | Uses iobj_DECLARE to declare interfaceable object. |
lifetime | |
mm_FREE | Static initializer. |
mm_INIT | Static initializer. |
call | |
malloc_mm | Calls mm->iimpl->malloc with mm->object as first parameter. |
mresize_mm | Calls mm->iimpl->mresize with mm->object as first parameter. |
mfree_mm | Calls mm->iimpl->mfree with mm->object as first parameter. |
sizeallocated_mm | Calls mm->iimpl->sizeallocated with mm->object as first parameter. |
mm_it | The function table describing the interface to a memory manager. |
malloc | See mm_impl_t.malloc_mmimpl for an implementation. |
mresize | See mm_impl_t.mresize_mmimpl for an implementation. |
mfree | See mm_impl_t.mfree_mmimpl for an implementation. |
sizeallocated | See mm_impl_t.sizeallocated_mmimpl for an implementation. |
lifetime | |
mm_it_FREE | Static initializer. |
mm_it_INIT | Static initializer. |
generic | |
genericcast_mmit | Casts parameter mminterface into pointer to interface mm_it. |
mm_it_DECLARE | Declares an interface function table for accessing a memory manager service. |
inline implementation | |
mm_t | |
malloc_mm | Implements mm_t.malloc_mm. |
mresize_mm | Implements mm_t.mresize_mm. |
mfree_mm | Implements mm_t.mfree_mm. |
sizeallocated_mm | Implements mm_t.sizeallocated_mm. |
mm_it | |
genericcast_mmit | Implements mm_it.genericcast_mmit. |
mm_it_DECLARE | Implements mm_it.mm_it_DECLARE. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2012 Jörg Seebohn
Header file of MemoryManager-Object.
Implements unittest MemoryManager-Object impl.
typedef struct mm_t mm_t
Export mm_t. Memory manager interfaceable object.
typedef struct mm_it mm_it
Export interface mm_it. See mm_it_DECLARE for adaption to a specific implementation.
test | |
unittest_memory_mm_mm | Test mm_it functionality. |
int unittest_memory_mm_mm( void )
Test mm_it functionality.
iobj_DECLARE( mm_t, mm )
Uses iobj_DECLARE to declare interfaceable object. See also mm_impl_t which is the default implementation.
lifetime | |
mm_FREE | Static initializer. |
mm_INIT | Static initializer. |
call | |
malloc_mm | Calls mm->iimpl->malloc with mm->object as first parameter. |
mresize_mm | Calls mm->iimpl->mresize with mm->object as first parameter. |
mfree_mm | Calls mm->iimpl->mfree with mm->object as first parameter. |
sizeallocated_mm | Calls mm->iimpl->sizeallocated with mm->object as first parameter. |
int malloc_mm( mm_t mm, size_t size, /*out*/struct memblock_t * memblock )
Calls mm->iimpl->malloc with mm->object as first parameter. See mm_it.malloc.
int mresize_mm( mm_t mm, size_t newsize, struct memblock_t * memblock )
Calls mm->iimpl->mresize with mm->object as first parameter. See mm_it.mresize.
int mfree_mm( mm_t mm, struct memblock_t * memblock )
Calls mm->iimpl->mfree with mm->object as first parameter. See mm_it.mfree.
size_t sizeallocated_mm( mm_t mm )
Calls mm->iimpl->sizeallocated with mm->object as first parameter. See mm_it.sizeallocated.
struct mm_it
The function table describing the interface to a memory manager. If you change the interface of mm_it to do not forget to adapt mm_it_DECLARE to the same signature.
malloc | See mm_impl_t.malloc_mmimpl for an implementation. |
mresize | See mm_impl_t.mresize_mmimpl for an implementation. |
mfree | See mm_impl_t.mfree_mmimpl for an implementation. |
sizeallocated | See mm_impl_t.sizeallocated_mmimpl for an implementation. |
lifetime | |
mm_it_FREE | Static initializer. |
mm_it_INIT | Static initializer. |
generic | |
genericcast_mmit | Casts parameter mminterface into pointer to interface mm_it. |
mm_it_DECLARE | Declares an interface function table for accessing a memory manager service. |
int ( * malloc ) (struct mm_t * mman, size_t size, /*out*/struct memblock_t * memblock)
See mm_impl_t.malloc_mmimpl for an implementation.
int ( * mresize ) (struct mm_t * mman, size_t newsize, struct memblock_t * memblock)
See mm_impl_t.mresize_mmimpl for an implementation.
int ( * mfree ) (struct mm_t * mman, struct memblock_t * memblock)
See mm_impl_t.mfree_mmimpl for an implementation.
size_t ( * sizeallocated ) (struct mm_t * mman)
See mm_impl_t.sizeallocated_mmimpl for an implementation.
#define mm_it_INIT( malloc_f, mresize_f, mfree_f, sizeallocated_f ) { (malloc_f), (mresize_f), (mfree_f), (sizeallocated_f) }
Static initializer. Set all function pointers to the provided values.
malloc_f | Function pointer to allocate a new memory block. See mm_it.malloc. |
mresize_f | Function pointer to allocate and resize memory. See mm_it.mresize. |
mfree_f | Function pointer to free memory blocks. See mm_it.mfree. |
sizeallocated_f | Function pointer to query the size of all allocated memory nlocks. See mm_it.sizeallocated. |
mm_it * genericcast_mmit( void * mminterface, TYPENAME memorymanager_t )
Casts parameter mminterface into pointer to interface mm_it. The parameter mminterface has to be of type pointer to type declared with mm_it_DECLARE. The other parameters must be the same as in mm_it_DECLARE without the first.
void mm_it_DECLARE( TYPENAME declared_it, TYPENAME memorymanager_t )
Declares an interface function table for accessing a memory manager service. The declared interface is structural compatible with the generic interface mm_it. The difference between the newly declared interface and the generic interface is the type of the object. Every interface function takes a pointer to this object type as its first parameter.
declared_it | The name of the structure which is declared as the interface. The name should have the suffix “_it”. |
memorymanager_t | The type of the memory manager object which is the first parameter of all interface functions. |
See mm_it for a list of declared functions.
mm_t | |
malloc_mm | Implements mm_t.malloc_mm. |
mresize_mm | Implements mm_t.mresize_mm. |
mfree_mm | Implements mm_t.mfree_mm. |
sizeallocated_mm | Implements mm_t.sizeallocated_mm. |
mm_it | |
genericcast_mmit | Implements mm_it.genericcast_mmit. |
mm_it_DECLARE | Implements mm_it.mm_it_DECLARE. |
#define malloc_mm( mm, size, /*out*/memblock ) ((mm).iimpl->malloc((mm).object, (size), (memblock)))
Implements mm_t.malloc_mm.
#define mresize_mm( mm, newsize, memblock ) ((mm).iimpl->mresize((mm).object, (newsize), (memblock)))
Implements mm_t.mresize_mm.
#define mfree_mm( mm, memblock ) ((mm).iimpl->mfree((mm).object, (memblock)))
Implements mm_t.mfree_mm.
#define sizeallocated_mm( mm ) ((mm).iimpl->sizeallocated((mm).object))
Implements mm_t.sizeallocated_mm.
#define genericcast_mmit( mminterface, memorymanager_t ) ( __extension__ ({ static_assert( &((typeof(mminterface))0)->malloc == (int (**) (memorymanager_t*, size_t, struct memblock_t*)) &((mm_it*)0)->malloc && &((typeof(mminterface))0)->mresize == (int (**) (memorymanager_t*, size_t, struct memblock_t*)) &((mm_it*)0)->mresize && &((typeof(mminterface))0)->mfree == (int (**) (memorymanager_t*, struct memblock_t*)) &((mm_it*)0)->mfree && &((typeof(mminterface))0)->sizeallocated == (size_t (**) (memorymanager_t*)) &((mm_it*)0)->sizeallocated, "ensure same structure") ; (mm_it*) (mminterface) ; }))
Implements mm_it.genericcast_mmit.
#define mm_it_DECLARE( declared_it, memorymanager_t ) typedef struct declared_it declared_it ; struct declared_it { int (* malloc) (memorymanager_t * mman, size_t size, /*out*/struct memblock_t * memblock) ; int (* mresize) (memorymanager_t * mman, size_t newsize, struct memblock_t * memblock) ; int (* mfree) (memorymanager_t * mman, struct memblock_t * memblock) ; size_t (* sizeallocated) (memorymanager_t * mman) ; } ;
Implements mm_it.mm_it_DECLARE.
Export mm_t.
typedef struct mm_t mm_t
Uses iobj_DECLARE to declare interfaceable object.
iobj_DECLARE( mm_t, mm )
Export interface mm_it.
typedef struct mm_it mm_it
The function table describing the interface to a memory manager.
struct mm_it
Test mm_it functionality.
int unittest_memory_mm_mm( void )
Implements iobj_t.iobj_DECLARE.
#define iobj_DECLARE( declared_t, typenameprefix ) struct declared_t { struct typenameprefix##_t * object ; struct typenameprefix##_it * iimpl ; }
Static initializer.
#define mm_FREE iobj_FREE
Static initializer.
#define mm_INIT( object, iimpl ) iobj_INIT(object, iimpl)
Calls mm->iimpl->malloc with mm->object as first parameter.
int malloc_mm( mm_t mm, size_t size, /*out*/struct memblock_t * memblock )
Calls mm->iimpl->mresize with mm->object as first parameter.
int mresize_mm( mm_t mm, size_t newsize, struct memblock_t * memblock )
Calls mm->iimpl->mfree with mm->object as first parameter.
int mfree_mm( mm_t mm, struct memblock_t * memblock )
Calls mm->iimpl->sizeallocated with mm->object as first parameter.
size_t sizeallocated_mm( mm_t mm )
See mm_impl_t.malloc_mmimpl for an implementation.
int ( * malloc ) (struct mm_t * mman, size_t size, /*out*/struct memblock_t * memblock)
Allocates new memory block.
int malloc_mmimpl( mm_impl_t * mman, size_t size, /*out*/struct memblock_t * memblock )
See mm_impl_t.mresize_mmimpl for an implementation.
int ( * mresize ) (struct mm_t * mman, size_t newsize, struct memblock_t * memblock)
Allocates new memory or resizes already allocated memory.
int mresize_mmimpl( mm_impl_t * mman, size_t newsize, struct memblock_t * memblock )
See mm_impl_t.mfree_mmimpl for an implementation.
int ( * mfree ) (struct mm_t * mman, struct memblock_t * memblock)
Frees the memory of an allocated memory block.
int mfree_mmimpl( mm_impl_t * mman, struct memblock_t * memblock )
See mm_impl_t.sizeallocated_mmimpl for an implementation.
size_t ( * sizeallocated ) (struct mm_t * mman)
Returns the size in bytes of all allocated memory blocks.
size_t sizeallocated_mmimpl( mm_impl_t * mman )
Static initializer.
#define mm_it_FREE { 0, 0, 0, 0 }
Static initializer.
#define mm_it_INIT( malloc_f, mresize_f, mfree_f, sizeallocated_f ) { (malloc_f), (mresize_f), (mfree_f), (sizeallocated_f) }
Casts parameter mminterface into pointer to interface mm_it.
mm_it * genericcast_mmit( void * mminterface, TYPENAME memorymanager_t )
Declares an interface function table for accessing a memory manager service.
void mm_it_DECLARE( TYPENAME declared_it, TYPENAME memorymanager_t )
Implements mm_t.malloc_mm.
#define malloc_mm( mm, size, /*out*/memblock ) ((mm).iimpl->malloc((mm).object, (size), (memblock)))
Implements mm_t.mresize_mm.
#define mresize_mm( mm, newsize, memblock ) ((mm).iimpl->mresize((mm).object, (newsize), (memblock)))
Implements mm_t.mfree_mm.
#define mfree_mm( mm, memblock ) ((mm).iimpl->mfree((mm).object, (memblock)))
Implements mm_t.sizeallocated_mm.
#define sizeallocated_mm( mm ) ((mm).iimpl->sizeallocated((mm).object))
Implements mm_it.genericcast_mmit.
#define genericcast_mmit( mminterface, memorymanager_t ) ( __extension__ ({ static_assert( &((typeof(mminterface))0)->malloc == (int (**) (memorymanager_t*, size_t, struct memblock_t*)) &((mm_it*)0)->malloc && &((typeof(mminterface))0)->mresize == (int (**) (memorymanager_t*, size_t, struct memblock_t*)) &((mm_it*)0)->mresize && &((typeof(mminterface))0)->mfree == (int (**) (memorymanager_t*, struct memblock_t*)) &((mm_it*)0)->mfree && &((typeof(mminterface))0)->sizeallocated == (size_t (**) (memorymanager_t*)) &((mm_it*)0)->sizeallocated, "ensure same structure") ; (mm_it*) (mminterface) ; }))
Implements mm_it.mm_it_DECLARE.
#define mm_it_DECLARE( declared_it, memorymanager_t ) typedef struct declared_it declared_it ; struct declared_it { int (* malloc) (memorymanager_t * mman, size_t size, /*out*/struct memblock_t * memblock) ; int (* mresize) (memorymanager_t * mman, size_t newsize, struct memblock_t * memblock) ; int (* mfree) (memorymanager_t * mman, struct memblock_t * memblock) ; size_t (* sizeallocated) (memorymanager_t * mman) ; } ;
Default memory manager for allocating/freeing blocks of memory.
struct mm_impl_t