This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 #include "dstm.h"
2
3 objstr_t *objstrCreate(unsigned int size)
4 {
5         objstr_t *tmp = malloc(sizeof(objstr_t) + size);
6         tmp->size = size;
7         tmp->top = tmp + 1; //points to end of objstr_t structure!
8         return tmp;
9 }
10
11 //free entire list, starting at store
12 void objstrDelete(objstr_t *store)
13 {
14         objstr_t *tmp;
15         while (store != NULL)
16         {
17                 tmp = store->next;
18                 free(store);
19                 store = tmp;
20         }
21         return;
22 }
23
24 void *objstrAlloc(objstr_t *store, unsigned int size)
25 {
26         void *tmp;
27         while (1)
28         {
29                 if (((unsigned int)store->top - (unsigned int)store - sizeof(objstr_t) + size) <= store->size)
30                 {  //store not full
31                         tmp = store->top;
32                         store->top += size;
33                         return tmp;
34                 }
35                 //store full
36                 if (store->next == NULL)
37                 {  //end of list, all full
38                         if (size > DEFAULT_OBJ_STORE_SIZE) //in case of large objects
39                         {
40                                 store->next = (objstr_t *)malloc(sizeof(objstr_t) + size);
41                                 store = store->next;
42                                 store->size = size;
43                         }
44                         else
45                         {
46                                 store->next = malloc(sizeof(objstr_t) + DEFAULT_OBJ_STORE_SIZE);
47                                 store = store->next;
48                                 store->size = DEFAULT_OBJ_STORE_SIZE;
49                         }
50                         store->top = (void *)((unsigned int)store + sizeof(objstr_t) + size);
51                         return (void *)((unsigned int)store + sizeof(objstr_t));
52                 }
53                 else  //try the next one
54                         store = store->next;
55         }
56 }
57