alternative Standard Libary  0.29.8
palloc.h-Dateireferenz

gehe zum Quellcode dieser Datei

Klassen

struct  palloc_t
 

Makrodefinitionen

#define MAX_PALLOC   1048576
 
#define PALLOC_SIZE   4
 
#define PALLOC_MAX_BLOCKS   (MAX_PALLOC / 32)
 

Funktionen

void pinit (uint64_t memsize)
 initialis the fixed block allocator with 512MB Mehr ...
 
void * palloc (size_t size)
 allocated memory Mehr ...
 
void pfree (void *addr)
 DeAlloceted the memory. Mehr ...
 
uint64_t ptotalsize ()
 get the total memory size Mehr ...
 
uint64_t pgetusable (void *m)
 get the to usable size of memory Mehr ...
 
uint64_t pusedmem ()
 get thebused memory Mehr ...
 

Makro-Dokumentation

◆ MAX_PALLOC

#define MAX_PALLOC   1048576

◆ PALLOC_MAX_BLOCKS

#define PALLOC_MAX_BLOCKS   (MAX_PALLOC / 32)

◆ PALLOC_SIZE

#define PALLOC_SIZE   4

Dokumentation der Funktionen

◆ palloc()

void* palloc ( size_t  size)

allocated memory

Parameter
sizeThe to allocated memory
69  {
70  unsigned addr, x, y, j, k;
71  int a, b, ff;
72 
73  for(x = 0; x < (pmm_page_number/32); x++) {
74  for (y = 0;y <32; y++) {
75  if((pmm_bitmap[x] & (1<<y)) == 0) {
76  a = x; b = y;
77  for(j = 0; j <= size; j++ ) {
78  if(j==size) {
79  pmm_bitmap[x] = pmm_bitmap[x] + (1<<y);
80  for(k = 1; k < size; k++) {
81  if(y == 31) {
82  y = 0;
83  x++;
84  } else {
85  y++;
86  }
87  pmm_bitmap[x] = pmm_bitmap[x] + (1<<y);
88  }
89  addr = (x)*(1024 * 32 * PALLOC_SIZE) + (y*1024*PALLOC_SIZE);
90  ff = palloc_first();
91  pmm_alloced[ff].dim = size;
92  pmm_alloced[ff].mem = (void*)addr;
93  return (void*)addr;
94  }
95  if(pisfree(&a, &b)) {
96  x = a;
97  y = b;
98  break;
99  }
100  }
101  }
102  }
103  }
104  return 0;
105 }
#define PALLOC_SIZE
Definition: palloc.h:40
uint8_t pisfree(int *x, int *y)
Definition: palloc.c:53
void * mem
Definition: palloc.h:44
size_t dim
Definition: palloc.h:45
unsigned pmm_bitmap[MAX_PALLOC]
Definition: palloc.c:30
uint64_t palloc_first()
Definition: palloc.c:62
unsigned pmm_page_number
Definition: palloc.c:31
palloc_t pmm_alloced[PALLOC_MAX_BLOCKS]
Definition: palloc.c:29

◆ pfree()

void pfree ( void *  addr)

DeAlloceted the memory.

Parameter
addrThe Memory to dealloceted
34  {
35  unsigned x, y;
36  for(uint64_t i=0; i < PALLOC_MAX_BLOCKS; i++) {
37  if(pmm_alloced[i].mem == addr) {
38  x = ((unsigned)addr/4096) / 32;
39  y = ((unsigned)addr/4096) % 32;
40  pmm_bitmap[x] = pmm_bitmap[x] - (1 << y);
41  for(uint64_t j = 1; j < pmm_alloced[i].dim; j++) {
42  if(y == 31) {
43  y = 0; x++;
44  } else {
45  y++;
46  }
47  pmm_bitmap[x] = pmm_bitmap[x] - (1 << y);
48  }
49  pmm_alloced[i].dim = 0;
50  }
51  }
52 }
#define PALLOC_MAX_BLOCKS
Definition: palloc.h:41
size_t dim
Definition: palloc.h:45
unsigned pmm_bitmap[MAX_PALLOC]
Definition: palloc.c:30
palloc_t pmm_alloced[PALLOC_MAX_BLOCKS]
Definition: palloc.c:29

◆ pgetusable()

uint64_t pgetusable ( void *  m)

get the to usable size of memory

Parameter
mThe to testing memory
109  {
110  for(int i = 0; i < PALLOC_MAX_BLOCKS; i++) {
111  if(pmm_alloced[i].mem == addr)
112  return pmm_alloced[i].dim;
113  }
114  return 0;
115 }
#define PALLOC_MAX_BLOCKS
Definition: palloc.h:41
size_t dim
Definition: palloc.h:45
palloc_t pmm_alloced[PALLOC_MAX_BLOCKS]
Definition: palloc.c:29

◆ pinit()

void pinit ( uint64_t  memsize)

initialis the fixed block allocator with 512MB

Parameter
memsizeThe used memory
129  {
130 
131  pmm_total = memsize;
132  pmm_page_number = ((((unsigned) pmm_total / PALLOC_SIZE) / 32) * 32);
133  for(unsigned x = 0; x < (pmm_page_number/32) ; x++)
134  pmm_bitmap[x] = 0;
135  for(unsigned x = 0; x < PALLOC_MAX_BLOCKS; x++) {
136  pmm_alloced[x].dim = 0;
137  }
138 
139 }
#define PALLOC_SIZE
Definition: palloc.h:40
uint64_t pmm_total
Definition: palloc.c:32
#define PALLOC_MAX_BLOCKS
Definition: palloc.h:41
size_t dim
Definition: palloc.h:45
unsigned pmm_bitmap[MAX_PALLOC]
Definition: palloc.c:30
unsigned pmm_page_number
Definition: palloc.c:31
palloc_t pmm_alloced[PALLOC_MAX_BLOCKS]
Definition: palloc.c:29

◆ ptotalsize()

uint64_t ptotalsize ( )

get the total memory size

106  {
107  return pmm_total;
108 }
uint64_t pmm_total
Definition: palloc.c:32

◆ pusedmem()

uint64_t pusedmem ( )

get thebused memory

126  {
127  return ((pmm_page_number - pgetfree()) * PALLOC_SIZE);
128 }
#define PALLOC_SIZE
Definition: palloc.h:40
uint64_t pgetfree()
Definition: palloc.c:116
unsigned pmm_page_number
Definition: palloc.c:31