| 83 | std::set<ExampleStruct *> ExampleStruct::items_freed; |
| 84 | |
| 85 | void |
| 86 | fillCache(RefCountCache<ExampleStruct> *cache, int start, int end) |
| 87 | { |
| 88 | // TODO: name per? |
| 89 | std::string name = "foobar"; |
| 90 | int allocSize = name.size() + 1; |
| 91 | |
| 92 | for (int i = start; i < end; i++) { |
| 93 | ExampleStruct *tmp = ExampleStruct::alloc(allocSize); |
| 94 | cache->put(static_cast<uint64_t>(i), tmp); |
| 95 | |
| 96 | tmp->idx = i; |
| 97 | tmp->name_offset = sizeof(ExampleStruct); |
| 98 | memcpy(tmp->name(), name.c_str(), name.size()); |
| 99 | // nullptr terminate the string |
| 100 | *(tmp->name() + name.size()) = '\0'; |
| 101 | |
| 102 | // Print out the struct we put in there |
| 103 | // printf("New ExampleStruct%d idx=%d name=%s allocSize=%d\n", i, tmp->idx, name.c_str(), allocSize); |
| 104 | } |
| 105 | printf("Loading complete! Cache now has %ld items.\n\n", cache->count()); |
| 106 | } |
| 107 | |
| 108 | int |
| 109 | verifyCache(RefCountCache<ExampleStruct> *cache, int start, int end) |