curr_odat(void);
struct vdat*
curr_vdat(void);
-struct ele*
-curr_ele(void);
struct set*
curr_set(void);
struct ref*
prev_ref(void);
-struct quad
-curr_quad(void);
struct model
curr_model(void);
void
inc_posts(void);
-#define CURR_CDAT (*cdat_stackp)
-#define CURR_SET set_list[CURR_CDAT->num_sets]
-#define CURR_ELE ele_list[CURR_CDAT->CURR_SET.num_ele]
-#define PREV_REF (ref_buf[num_refs-1])
-#define CURR_REF (ref_buf[num_refs])
-#define PREV_ODAT (odat_buf[num_odats-1])
-#define CURR_ODAT (odat_buf[num_odats])
-#define CURR_VDAT (vdat_buf[num_vdats])
-#define PREV_VDAT (vdat_buf[num_vdats-1])
-#define CURR_MODEL (CURR_VDAT->model_list[CURR_VDAT->num_models])
-#define CURR_LINK (link_buf[num_links])
-#define CURR_POST (post_buf[num_posts])
-#define CURR_QUAD (CURR_ODAT->quad_list[CURR_ODAT->num_quads])
-
-
-int num_cdats = -1;
+#define CURR_CDAT (*cdat_stackp)
+#define CURR_SET set_list[CURR_CDAT->num_sets]
+#define REF_IDX (num_refs % (refs_per_page * pages_per_chunk))
+#define PREV_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize - (sizeof (struct ref))))
+#define CURR_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize))
+#define ODAT_IDX (num_odats % (odats_per_page * pages_per_chunk))
+#define CURR_ODAT (odat_buf[num_odat_chunks] + (ODAT_IDX * (sizeof (struct odat)) + pagesize))
+#define VDAT_IDX (num_vdats % (vdats_per_page * pages_per_chunk))
+#define CURR_VDAT (vdat_buf[num_vdat_chunks] + (VDAT_IDX * (sizeof (struct vdat)) + pagesize))
+#define CURR_MODEL (CURR_VDAT.model_list[CURR_VDAT.num_models])
+#define CURR_LINK (link_buf[num_links])
+#define CURR_POST (post_buf[num_posts])
+#define CURR_QUAD (CURR_ODAT->quad_file)
+
+long pagesize;
+
+int pages_per_chunk = 10;
+
+int num_cdats = 0;
int curr_max_cdats = PTRS_IN_PAGE;
struct cdat* cdat_buf[PTRS_IN_PAGE];
struct cdat** cdat_stackp;
-int num_odats = -1;
-int curr_max_odats = PTRS_IN_PAGE;
-struct odat* odat_buf[PTRS_IN_PAGE];
-
-
-int num_vdats = -1;
-int curr_max_vdats = PTRS_IN_PAGE;
-struct vdat* vdat_buf[PTRS_IN_PAGE];
-
-
-int num_refs = -1;
-int curr_max_refs = PTRS_IN_PAGE;
-struct ref* ref_buf[PTRS_IN_PAGE];
+int num_odat_chunks = 0;
+int num_odats = 0;
+void* odat_buf[MAX_CHUNKS];
+long odats_per_page;
+
+
+//"type free" chunk stacking
+struct chunk_stack
+{ void* chunks[MAX_CHUNKS];
+ void* csp; //chunk stack pointer
+ void* dsp[MAX_CHUNKS]; //dat stack pointer (per chunk)
+} ocs, vcs, ccs; //odat, vdat, and cdat chunk stacks
+
+//type safety handled by macro expansion
+#define CHUNK_LEN(STACK) ((STACK).csp - (STACK).chunks)
+#define CURRENT_DAT(STACK,TYPE) ((TYPE)(STACK.dsp[CHUNK_LEN(STACK)])
+#define INCREMENT_DAT(STACK,TYPE) (++CURRENT_DAT(STACK,TYPE))
+//Stack-specific macros
+#define CURRENT_ODAT() (CURRENT_DAT(ocs,struct odat*))
+#define CURRENT_VDAT() (CURRENT_DAT(vcs,struct vdat*))
+#define CURRENT_CDAT() (CURRENT_DAT(ccs,struct cdat*))
+//Metadata
+#define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
+
+
+int num_vdat_chunks = 0;
+int num_vdats = 0;
+struct vdat* vdat_buf[MAX_CHUNKS];
+long vdats_per_page;
+
+int num_ref_chunks = 0;
+int num_refs = 0;
+void* ref_buf[MAX_CHUNKS];
+long refs_per_page;
uint64_t ss_ref_id = 0x00FFFFFF; /* system space for ref_ids */
int num_posts = -1;
/* The initalization function of the IR. */
-void
+int
ir_init()
{
/* Init root cdat and stack */
char root[4] = "root";
- cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof(struct cdat) );
- cdat_buf[num_cdats]->idx = 0;
+ if( (cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof(struct cdat))) == NULL)
+ {
+ perror("malloc root class failed\n");
+ return -1;
+ }
+ cdat_buf[num_cdats]->idx = num_cdats;
memmove(cdat_buf[num_cdats]->name, root, 4);
cdat_stackp = cdat_stack;
*cdat_stackp++ = cdat_buf[num_cdats++];
+ pagesize = sysconf(_SC_PAGESIZE);
+ odats_per_page = (sizeof (struct odat)/pagesize);
+ vdats_per_page = (sizeof (struct vdat)/pagesize);
+ refs_per_page = (sizeof (struct ref)/pagesize);
+
+ return 0;
+
+}
+
+void
+ir_quit()
+{
+ int i;
+
+ for(i = 0; i <= num_odats ; i++)
+ {
+ free(odat_buf[i]);
+ }
+ for(i = 0; i <= num_cdats; i++)
+ {
+ free(cdat_buf[i]);
+ }
+ for(i = 0; i <= num_vdats; i++)
+ {
+ free(vdat_buf[i]);
+ }
+ for(i = 0; i <= num_refs; i++)
+ {
+ free(ref_buf[i]);
+ }
+ for(i = 0; i<= num_links; i++)
+ {
+ free(link_buf[i]);
+ }
+
}
//TODO: FREE MEMORY!
alloc_odat
()
{
-
num_odats++;
- if(num_odats >= curr_max_odats)
- { if( (realloc((void*) odat_buf, PTRS_IN_PAGE * 4)) == NULL)
- perror("realloc odat_buf failed");
- curr_max_odats += PTRS_IN_PAGE;
+
+ if(!(num_odats % (odats_per_page * pages_per_chunk))) //chunk is full
+ {
+ num_odat_chunks++;
+ if( ((odat_buf[num_odat_chunks] = malloc(odats_per_page * pages_per_chunk)) == NULL) )
+ perror("malloc odat chunk failed");
}
- if( (CURR_ODAT = (struct odat*) malloc(sizeof (struct odat))) == NULL)
- perror("malloc odat failed");
return CURR_ODAT;
}
()
{
num_vdats++;
- if(num_vdats >= curr_max_vdats)
- { if( (realloc((void*) vdat_buf, PTRS_IN_PAGE * 4)) == NULL)
- perror("realloc vdat_buf failed");
- curr_max_vdats += PTRS_IN_PAGE;
+
+ if(!(num_vdats % (vdats_per_page * pages_per_chunk))) //chunk is full
+ {
+ num_vdat_chunks++;
+ if( ((vdat_buf[num_vdat_chunks] = malloc(vdats_per_page * pages_per_chunk)) == NULL) )
+ perror("malloc vdat chunk failed");
}
- if((CURR_VDAT = (struct vdat*) malloc(sizeof (struct vdat))) == NULL)
- perror("malloc vdat failed");
}
{ CURR_POST = CURR_REF;
inc_posts();
}
-
- if(num_refs >= curr_max_refs)
- { if( (realloc((void*) ref_buf, PTRS_IN_PAGE * 4)) == NULL)
- perror("realloc ref_buf failed");
- curr_max_refs += PTRS_IN_PAGE;
+ if(!(num_refs % (refs_per_page * pages_per_chunk))) //chunk is full
+ {
+ num_ref_chunks++;
+ if( ((ref_buf[num_ref_chunks] = malloc(refs_per_page * pages_per_chunk)) == NULL) )
+ perror("malloc ref chunk failed");
}
- if((CURR_REF = (struct ref*) malloc(sizeof (struct ref))) == NULL)
- perror("malloc ref failed");
return CURR_REF;
}
{
return &CURR_CDAT->CURR_SET;
}
-struct ele*
-curr_ele
-()
-{
- return &CURR_CDAT->CURR_SET.CURR_ELE;
-}
struct ref*
prev_ref
()
{
return PREV_REF;
}
-
-struct quad
-curr_quad
-()
-{
- return CURR_QUAD;
-}
struct model
curr_model
()