DefaultMemoryManager

Default implementation of mm_it.  // TODO: rename into mm_default

Summary
DefaultMemoryManagerDefault implementation of mm_it.
CopyrightThis program is free software.
Files
C-kern/api/memory/mm/mm_impl.hHeader file DefaultMemoryManager.
C-kern/memory/mm/mm_impl.cImplementation file DefaultMemoryManager impl.
Types
struct mm_impl_tExports mm_impl_t.
Functions
test
unittest_memory_mm_mmimplTest default memory manager mm_impl_t.
mm_impl_tDefault memory manager for allocating/freeing blocks of memory.
initthread
interface_mmimplThis function is called from <init_threadcontext>.
lifetime
mmimpl_FREEStatic initializer.
init_mmimplInitializes a new memory manager.
free_mmimplFrees all memory managed by this manager.
query
sizeallocated_mmimplReturns the size in bytes of all allocated memory blocks.
allocate
malloc_mmimplAllocates new memory block.
mresize_mmimplAllocates new memory or resizes already allocated memory.
mfree_mmimplFrees the memory of an allocated memory block.

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_impl.h

C-kern/memory/mm/mm_impl.c

Implementation file DefaultMemoryManager impl.

Types

struct mm_impl_t

typedef struct mm_impl_t mm_impl_t

Exports mm_impl_t.

Functions

Summary
test
unittest_memory_mm_mmimplTest default memory manager mm_impl_t.

test

unittest_memory_mm_mmimpl

int unittest_memory_mm_mmimpl(void)

Test default memory manager mm_impl_t.

mm_impl_t

struct mm_impl_t

Default memory manager for allocating/freeing blocks of memory.

Summary
initthread
interface_mmimplThis function is called from <init_threadcontext>.
lifetime
mmimpl_FREEStatic initializer.
init_mmimplInitializes a new memory manager.
free_mmimplFrees all memory managed by this manager.
query
sizeallocated_mmimplReturns the size in bytes of all allocated memory blocks.
allocate
malloc_mmimplAllocates new memory block.
mresize_mmimplAllocates new memory or resizes already allocated memory.
mfree_mmimplFrees the memory of an allocated memory block.

initthread

interface_mmimpl

struct mm_it * interface_mmimpl(void)

This function is called from <init_threadcontext>.  Used to initialize interface of mm_t.

lifetime

mmimpl_FREE

#define mmimpl_FREE { 0 }

Static initializer.

init_mmimpl

int init_mmimpl(/*out*/mm_impl_t *mman)

Initializes a new memory manager.

free_mmimpl

int free_mmimpl(mm_impl_t *mman)

Frees all memory managed by this manager.  Beofre freeing it make sure that every object allocated on this memory heap is no more reachable or already freed.

query

sizeallocated_mmimpl

size_t sizeallocated_mmimpl(mm_impl_t *mman)

Returns the size in bytes of all allocated memory blocks.  If this value is 0 no memory is allocated on this heap.

allocate

malloc_mmimpl

int malloc_mmimpl(mm_impl_t *mman,
size_t size,
/*out*/struct memblock_t *memblock)

Allocates new memory block.

On successful return the field memblock_t.size can be set to a larger value than provided in size to allow the memory manager for some internal optimization.  To free a memory block it is enough to call mfree_mmimpl with the returned memblock.  It is allowed to set memblock_t.size to the same value as provided in argument size.

mresize_mmimpl

int mresize_mmimpl(mm_impl_t *mman,
size_t newsize,
struct memblock_t *memblock)

Allocates new memory or resizes already allocated memory.  Allocation is a special case in that it is a resize operation with the size and addr of parameter memblock_t set to 0.

Before calling this function make sure that memblock is either set to <memblock_FREE> or to a value returned by a previous call to malloc_mmimpl or this function.

On successful return the field memblock_t.size can be set to a larger value than provided in newsize to allow the memory manager for some internal optimization.  To free a memory block it is enough to call mfree_mmimpl with the returned memblock.  It is allowed to set memblock_t.size to the same value as provided in argument newsize.

mfree_mmimpl

int mfree_mmimpl(mm_impl_t *mman,
struct memblock_t *memblock)

Frees the memory of an allocated memory block.  After return memblock is set to <memblock_FREE>.  This ensured that calling this function twice with the same argument is a no op.

struct mm_it
The function table describing the interface to a memory manager.
Default implementation of mm_it.
Implements DefaultMemoryManager.
typedef struct mm_impl_t mm_impl_t
Exports mm_impl_t.
struct mm_impl_t
Default memory manager for allocating/freeing blocks of memory.
int unittest_memory_mm_mmimpl(void)
Test default memory manager mm_impl_t.
struct mm_it * interface_mmimpl(void)
This function is called from init_threadcontext.
#define mmimpl_FREE { 0 }
Static initializer.
int init_mmimpl(/*out*/mm_impl_t *mman)
Initializes a new memory manager.
int free_mmimpl(mm_impl_t *mman)
Frees all memory managed by this manager.
size_t sizeallocated_mmimpl(mm_impl_t *mman)
Returns the size in bytes of all allocated memory blocks.
int malloc_mmimpl(mm_impl_t *mman,
size_t size,
/*out*/struct memblock_t *memblock)
Allocates new memory block.
int mresize_mmimpl(mm_impl_t *mman,
size_t newsize,
struct memblock_t *memblock)
Allocates new memory or resizes already allocated memory.
int mfree_mmimpl(mm_impl_t *mman,
struct memblock_t *memblock)
Frees the memory of an allocated memory block.
iobj_DECLARE(mm_t,
mm)
Uses iobj_DECLARE to declare interfaceable object.
size_t size
Size of memory in bytes addr points to.
struct memblock_t
Describes memory block.
Close