MemoryManager-Object

Defines interfaceable object which offers memory manager functionality.  Implemented by mm_impl_t.

Summary
MemoryManager-ObjectDefines interfaceable object which offers memory manager functionality.
CopyrightThis program is free software.
Files
C-kern/api/memory/mm/mm.hHeader file of MemoryManager-Object.
C-kern/memory/mm/mm.cImplements unittest MemoryManager-Object impl.
Types
struct mm_tExport mm_t.
struct mm_itExport interface mm_it.
Functions
test
unittest_memory_mm_mmTest mm_it functionality.
mm_tUses iobj_DECLARE to declare interfaceable object.
lifetime
mm_FREEStatic initializer.
mm_INITStatic initializer.
call
malloc_mmCalls mm->iimpl->malloc with mm->object as first parameter.
mresize_mmCalls mm->iimpl->mresize with mm->object as first parameter.
mfree_mmCalls mm->iimpl->mfree with mm->object as first parameter.
sizeallocated_mmCalls mm->iimpl->sizeallocated with mm->object as first parameter.
mm_itThe function table describing the interface to a memory manager.
mallocSee mm_impl_t.malloc_mmimpl for an implementation.
mresizeSee mm_impl_t.mresize_mmimpl for an implementation.
mfreeSee mm_impl_t.mfree_mmimpl for an implementation.
sizeallocatedSee mm_impl_t.sizeallocated_mmimpl for an implementation.
lifetime
mm_it_FREEStatic initializer.
mm_it_INITStatic initializer.
generic
genericcast_mmitCasts parameter mminterface into pointer to interface mm_it.
mm_it_DECLAREDeclares an interface function table for accessing a memory manager service.
inline implementation
mm_t
malloc_mmImplements mm_t.malloc_mm.
mresize_mmImplements mm_t.mresize_mm.
mfree_mmImplements mm_t.mfree_mm.
sizeallocated_mmImplements mm_t.sizeallocated_mm.
mm_it
genericcast_mmitImplements mm_it.genericcast_mmit.
mm_it_DECLAREImplements mm_it.mm_it_DECLARE.

Copyright

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.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/memory/mm/mm.h

Header file of MemoryManager-Object.

C-kern/memory/mm/mm.c

Implements unittest MemoryManager-Object impl.

Types

struct mm_t

typedef struct mm_t mm_t

Export mm_t.  Memory manager interfaceable object.

struct mm_it

typedef struct mm_it mm_it

Export interface mm_it.  See mm_it_DECLARE for adaption to a specific implementation.

Functions

Summary
test
unittest_memory_mm_mmTest mm_it functionality.

test

unittest_memory_mm_mm

int unittest_memory_mm_mm(void)

Test mm_it functionality.

mm_t

iobj_DECLARE(mm_t,
mm)

Uses iobj_DECLARE to declare interfaceable object.  See also mm_impl_t which is the default implementation.

Summary
lifetime
mm_FREEStatic initializer.
mm_INITStatic initializer.
call
malloc_mmCalls mm->iimpl->malloc with mm->object as first parameter.
mresize_mmCalls mm->iimpl->mresize with mm->object as first parameter.
mfree_mmCalls mm->iimpl->mfree with mm->object as first parameter.
sizeallocated_mmCalls mm->iimpl->sizeallocated with mm->object as first parameter.

lifetime

mm_FREE

#define mm_FREE iobj_FREE

Static initializer.

mm_INIT

#define mm_INIT(object,
iimpl) iobj_INIT(object, iimpl)

Static initializer.

call

malloc_mm

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.

mresize_mm

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.

mfree_mm

int mfree_mm(mm_t mm,
struct memblock_t *memblock)

Calls mm->iimpl->mfree with mm->object as first parameter.  See mm_it.mfree.

sizeallocated_mm

size_t sizeallocated_mm(mm_t mm)

Calls mm->iimpl->sizeallocated with mm->object as first parameter.  See mm_it.sizeallocated.

mm_it

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.

Summary
mallocSee mm_impl_t.malloc_mmimpl for an implementation.
mresizeSee mm_impl_t.mresize_mmimpl for an implementation.
mfreeSee mm_impl_t.mfree_mmimpl for an implementation.
sizeallocatedSee mm_impl_t.sizeallocated_mmimpl for an implementation.
lifetime
mm_it_FREEStatic initializer.
mm_it_INITStatic initializer.
generic
genericcast_mmitCasts parameter mminterface into pointer to interface mm_it.
mm_it_DECLAREDeclares an interface function table for accessing a memory manager service.

malloc

int (
   *malloc
) (struct mm_t * mman, size_t size, /*out*/struct memblock_t * memblock)

See mm_impl_t.malloc_mmimpl for an implementation.

mresize

int (
   *mresize
) (struct mm_t * mman, size_t newsize, struct memblock_t * memblock)

See mm_impl_t.mresize_mmimpl for an implementation.

mfree

int (*mfree) (struct mm_t * mman, struct memblock_t * memblock)

See mm_impl_t.mfree_mmimpl for an implementation.

sizeallocated

size_t (*sizeallocated) (struct mm_t * mman)

See mm_impl_t.sizeallocated_mmimpl for an implementation.

lifetime

mm_it_FREE

#define mm_it_FREE { 0, 0, 0, 0 }

Static initializer.  Set all fields to 0.

mm_it_INIT

#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.

Parameters

malloc_fFunction pointer to allocate a new memory block.  See mm_it.malloc.
mresize_fFunction pointer to allocate and resize memory.  See mm_it.mresize.
mfree_fFunction pointer to free memory blocks.  See mm_it.mfree.
sizeallocated_fFunction pointer to query the size of all allocated memory nlocks.  See mm_it.sizeallocated.

generic

genericcast_mmit

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.

mm_it_DECLARE

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.

Parameter

declared_itThe name of the structure which is declared as the interface.  The name should have the suffix “_it”.
memorymanager_tThe 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

#define malloc_mm(
   mm,
   size,
   /*out*/memblock
) ((mm).iimpl->malloc((mm).object, (size), (memblock)))

Implements mm_t.malloc_mm.

mresize_mm

#define mresize_mm(
   mm,
   newsize,
   memblock
) ((mm).iimpl->mresize((mm).object, (newsize), (memblock)))

Implements mm_t.mresize_mm.

mfree_mm

#define mfree_mm(mm,
memblock) ((mm).iimpl->mfree((mm).object, (memblock)))

Implements mm_t.mfree_mm.

sizeallocated_mm

#define sizeallocated_mm(mm) ((mm).iimpl->sizeallocated((mm).object))

Implements mm_t.sizeallocated_mm.

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.genericcast_mmit.

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) ; } ;

Implements mm_it.mm_it_DECLARE.

Defines interfaceable object which offers memory manager functionality.
Implements unittest of MemoryManager-Object.
typedef struct mm_t mm_t
Export mm_t.
iobj_DECLARE(mm_t,
mm)
Uses iobj_DECLARE to declare interfaceable object.
typedef struct mm_it mm_it
Export interface mm_it.
struct mm_it
The function table describing the interface to a memory manager.
int unittest_memory_mm_mm(void)
Test mm_it functionality.
#define iobj_DECLARE(
   declared_t,
   typenameprefix
) struct declared_t { struct typenameprefix##_t * object ; struct typenameprefix##_it * iimpl ; }
Implements iobj_t.iobj_DECLARE.
#define mm_FREE iobj_FREE
Static initializer.
#define mm_INIT(object,
iimpl) iobj_INIT(object, iimpl)
Static initializer.
int malloc_mm(mm_t mm,
size_t size,
/*out*/struct memblock_t *memblock)
Calls mm->iimpl->malloc with mm->object as first parameter.
int mresize_mm(mm_t mm,
size_t newsize,
struct memblock_t *memblock)
Calls mm->iimpl->mresize with mm->object as first parameter.
int mfree_mm(mm_t mm,
struct memblock_t *memblock)
Calls mm->iimpl->mfree with mm->object as first parameter.
size_t sizeallocated_mm(mm_t mm)
Calls mm->iimpl->sizeallocated with mm->object as first parameter.
int (
   *malloc
) (struct mm_t * mman, size_t size, /*out*/struct memblock_t * memblock)
See mm_impl_t.malloc_mmimpl for an implementation.
int malloc_mmimpl(mm_impl_t *mman,
size_t size,
/*out*/struct memblock_t *memblock)
Allocates new memory block.
int (
   *mresize
) (struct mm_t * mman, size_t newsize, struct memblock_t * memblock)
See mm_impl_t.mresize_mmimpl for an implementation.
int mresize_mmimpl(mm_impl_t *mman,
size_t newsize,
struct memblock_t *memblock)
Allocates new memory or resizes already allocated memory.
int (*mfree) (struct mm_t * mman, struct memblock_t * memblock)
See mm_impl_t.mfree_mmimpl for an implementation.
int mfree_mmimpl(mm_impl_t *mman,
struct memblock_t *memblock)
Frees the memory of an allocated memory block.
size_t (*sizeallocated) (struct mm_t * mman)
See mm_impl_t.sizeallocated_mmimpl for an implementation.
size_t sizeallocated_mmimpl(mm_impl_t *mman)
Returns the size in bytes of all allocated memory blocks.
#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) }
Static initializer.
mm_it * genericcast_mmit(void *mminterface,
TYPENAME memorymanager_t)
Casts parameter mminterface into pointer to interface mm_it.
void mm_it_DECLARE(TYPENAME declared_it,
TYPENAME memorymanager_t)
Declares an interface function table for accessing a memory manager service.
#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.
struct mm_impl_t
Default memory manager for allocating/freeing blocks of memory.
Close