Turnstone Operating System
Loading...
Searching...
No Matches
memory.h File Reference

memory functions More...

#include <types.h>

Classes

struct  memory_heap_stat_t
 heap statistics, both monitoring and leak analysis. More...
 
struct  memory_heap_t
 heap interface for all types More...
 

Macros

#define ___MEMORY_H   0
 
#define memory_get_heap_stat(s)   memory_get_heap_stat_ext(NULL, s)
 
#define memory_free(addr)   memory_free_ext(NULL, addr)
 
#define memory_malloc(s)   memory_malloc_ext(NULL, s, 0x0)
 
#define memory_malloc_aligned(s, a)   memory_malloc_ext(NULL, s, a)
 

Typedefs

typedef struct lock_t lock_t
 
typedef struct memory_heap_stat_t memory_heap_stat_t
 short hand for struct
 
typedef struct memory_heap_t memory_heap_t
 short hand for struct
 

Functions

memory_heap_tmemory_create_heap_simple (size_t start, size_t end)
 creates simple heap More...
 
memory_heap_tmemory_create_heap_hash (size_t start, size_t end)
 creates hash backended heap More...
 
memory_heap_tmemory_set_default_heap (memory_heap_t *heap)
 sets default heap More...
 
memory_heap_tmemory_get_default_heap (void)
 
memory_heap_tmemory_get_heap (memory_heap_t *heap)
 returns heap, finds correct heap for task. More...
 
void memory_get_heap_stat_ext (memory_heap_t *heap, memory_heap_stat_t *stat)
 returns stats for heap More...
 
int8_t memory_free_ext (memory_heap_t *heap, void *address)
 frees memory More...
 
void * memory_malloc_ext (memory_heap_t *heap, size_t size, size_t align)
 malloc memory More...
 
int8_t memory_memset (void *address, uint8_t value, size_t size)
 sets memory with value More...
 
int8_t memory_memclean (void *address, size_t size)
 zeros memory More...
 
int8_t memory_memcopy (const void *source, void *destination, size_t size)
 copy source to destination with length bytes from source More...
 
int8_t memory_memcompare (const void *mem1, const void *mem2, size_t size)
 compares first length bytes of mem1 with mem2 More...
 

Detailed Description

memory functions

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ ___MEMORY_H

#define ___MEMORY_H   0

prevent duplicate header error macro

◆ memory_free

#define memory_free (   addr)    memory_free_ext(NULL, addr)

frees memory addr at default heap

◆ memory_get_heap_stat

#define memory_get_heap_stat (   s)    memory_get_heap_stat_ext(NULL, s)

returns stats for default heap

◆ memory_malloc

#define memory_malloc (   s)    memory_malloc_ext(NULL, s, 0x0)

malloc with size s at default heap without aligned

◆ memory_malloc_aligned

#define memory_malloc_aligned (   s,
 
)    memory_malloc_ext(NULL, s, a)

malloc with size s at default heap with aligned a

Typedef Documentation

◆ lock_t

typedef struct lock_t lock_t

lock type preventing sync.h recursion

Function Documentation

◆ memory_create_heap_hash()

memory_heap_t * memory_create_heap_hash ( size_t  start,
size_t  end 
)

creates hash backended heap

Parameters
[in]startstart address of heap
[in]endend address of heap
Returns
heap

◆ memory_create_heap_simple()

memory_heap_t * memory_create_heap_simple ( size_t  start,
size_t  end 
)

creates simple heap

Parameters
[in]startstart address of heap
[in]endend address of heap
Returns
heap

◆ memory_free_ext()

int8_t memory_free_ext ( memory_heap_t heap,
void *  address 
)

frees memory

Parameters
[in]heapthe heap where the address is.
[in]addressaddress to free
Returns
0 if successed.

if heap is NULL, address will be freed at default heap

◆ memory_get_heap()

memory_heap_t * memory_get_heap ( memory_heap_t heap)

returns heap, finds correct heap for task.

Returns
correct heap for task

◆ memory_get_heap_stat_ext()

void memory_get_heap_stat_ext ( memory_heap_t heap,
memory_heap_stat_t stat 
)

returns stats for heap

Parameters
[in]heapheap which stats will be collected
[out]statreturned stats

◆ memory_malloc_ext()

void * memory_malloc_ext ( memory_heap_t heap,
size_t  size,
size_t  align 
)

malloc memory

Parameters
[in]heapthe heap used for malloc
[in]sizesize of variable
[in]alignaddress of variable aligned at.
Returns
address of variable

if heap is NULL, variable allocated at default heap.

◆ memory_memclean()

int8_t memory_memclean ( void *  address,
size_t  size 
)

zeros memory

Parameters
[in]athe address to be zerod.
[in]srepeat count
Returns
0

◆ memory_memcompare()

int8_t memory_memcompare ( const void *  mem1,
const void *  mem2,
size_t  size 
)

compares first length bytes of mem1 with mem2

Parameters
mem1first memory address
mem2second memory address
sizecount of bytes for compare
Returns
<0 if mem1>mem2, 0 if mem1=mem2, >0 if mem1>mem2

◆ memory_memcopy()

int8_t memory_memcopy ( const void *  source,
void *  destination,
size_t  size 
)

copy source to destination with length bytes from source

Parameters
[in]sourcesource address
[in]destinationdestination address
[in]sizehow many bytes will be copied
Returns
0

if destination is smaller then length a memory corruption will be happend

◆ memory_memset()

int8_t memory_memset ( void *  address,
uint8_t  value,
size_t  size 
)

sets memory with value

Parameters
[in]addressthe address to be setted.
[in]valuethe value
[in]sizerepeat count
Returns
0

◆ memory_set_default_heap()

memory_heap_t * memory_set_default_heap ( memory_heap_t heap)

sets default heap

Parameters
[in]heapthe heap will be the default one
Returns
old default heap