Testing vector indexing

This commit is contained in:
Victor Olin 2023-03-23 13:32:24 +01:00
parent fb4cd8eb9b
commit e745593d94
2 changed files with 14 additions and 11 deletions

View file

@ -130,7 +130,8 @@ namespace GC
// Check if there are any freed chunks large enough for current request
for (size_t i = 0; i < heap.m_freed_chunks.size(); i++)
{
auto chunk = Heap::get_at(heap.m_freed_chunks, i);
// auto chunk = Heap::get_at(heap.m_freed_chunks, i);
auto chunk = heap.m_freed_chunks[i];
auto iter = heap.m_freed_chunks.begin();
advance(iter, i);
if (chunk->m_size > size)
@ -373,14 +374,16 @@ namespace GC
{
std::vector<Chunk *> filtered;
size_t i = 0;
auto prev = Heap::get_at(heap.m_freed_chunks, i++);
// auto prev = Heap::get_at(heap.m_freed_chunks, i++);
auto prev = heap.m_freed_chunks[i++];
prev->m_marked = true;
filtered.push_back(prev);
cout << filtered.back()->m_start << endl;
for (; i < heap.m_freed_chunks.size(); i++)
{
prev = filtered.back();
auto next = Heap::get_at(heap.m_freed_chunks, i);
// auto next = Heap::get_at(heap.m_freed_chunks, i);
auto next = heap.m_freed_chunks[i];
auto p_start = (uintptr_t)(prev->m_start);
auto p_size = (uintptr_t)(prev->m_size);
auto n_start = (uintptr_t)(next->m_start);

View file

@ -67,9 +67,9 @@ void test_some_types() {
int main() {
GC::Heap::init();
GC::Heap *gc = GC::Heap::debug_the();
gc->set_profiler(true);
gc->check_init();
GC::Heap &gc = GC::Heap::the();
gc.set_profiler(true);
gc.check_init();
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
std::cout << "Stack start from main:\t" << stack_start << std::endl;
@ -86,7 +86,7 @@ int main() {
longs++;
} */
Node *root = static_cast<Node *>(gc->alloc(sizeof(Node)));
Node *root = static_cast<Node *>(gc.alloc(sizeof(Node)));
root = test_chain(3, false);
Node *root_child = root->child;
std::cout << "Adress of root:\t" << &root << std::endl;
@ -95,9 +95,9 @@ int main() {
std::cout << "Root child, child:\t" << root_child->child << std::endl;
gc->collect(GC::COLLECT_ALL);
gc->print_contents();
gc.collect(GC::COLLECT_ALL);
gc.print_contents();
gc->dispose();
gc.dispose();
return 0;
}