Skip to content

Commit

Permalink
Actually allocate data blocks and add them to the free list during in…
Browse files Browse the repository at this point in the history
…itialization
  • Loading branch information
Andrew Kallem committed Oct 13, 2014
1 parent 8735419 commit 8034468
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void printListBackward(ListNode *tail) {
}

void init(int node_nr) {
int h, t, p;
int h, t, p, i;
free_list = new List **[tags];
busy_list = new HashList **[tags];
full_list = new List **[tags];
Expand All @@ -104,6 +104,16 @@ void init(int node_nr) {
free_list[t][p] = new List[node_nr];
busy_list[t][p] = new HashList[node_nr];
full_list[t][p] = new List[node_nr];

for (i = 0; i < MAX_BLOCKS_PER_LIST; i++) {
struct DataBlock db;
db.data = malloc(BLOCK_SIZE);

ListNode *node = new ListNode;
node->db = db;

free_list[t][p][node_nr].addTail(node);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion usertype.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define BLOCK_SIZE 4096
#define BUFFER_SIZE 4096 //set BUFFER_SIZE equal to BLOCK_SIZE to read one block of data each time
#define AVAL_BLOCKS 10000 //total number of available blocks in BLOCKPTRS
#define MAX_BLOCKS_PER_LIST 10 // Number of blocks initially allocated to the free lists

using namespace std;

Expand Down

0 comments on commit 8034468

Please sign in to comment.