Add fetchSublist method to BinaryTable for improved data retrieval
This commit is contained in:
61
cpp/debug/debug_alloc.cpp
Normal file
61
cpp/debug/debug_alloc.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include "../binary_table.h"
|
||||
|
||||
int main() {
|
||||
using namespace bt;
|
||||
|
||||
const std::string filename = "debug_alloc.bin";
|
||||
if (std::filesystem::exists(filename)) {
|
||||
std::filesystem::remove(filename);
|
||||
}
|
||||
|
||||
BinaryTable table(filename);
|
||||
table.initialize();
|
||||
|
||||
std::cout << "=== Testing Memory Allocation Issues ===\n" << std::endl;
|
||||
|
||||
// Store first key and see what address it gets
|
||||
std::cout << "1. Storing first key..." << std::endl;
|
||||
table.set<int32_t>("key1", 100);
|
||||
|
||||
// Get the address where key1's value was stored
|
||||
auto addressTable1 = table.getReference("key1").getPointer();
|
||||
std::cout << " key1 value stored at: " << addressTable1.address() << std::endl;
|
||||
|
||||
// Store second key and see what addresses are used
|
||||
std::cout << "2. Storing second key..." << std::endl;
|
||||
table.set<int32_t>("key2", 200);
|
||||
|
||||
auto addressTable2 = table.getReference("key2").getPointer();
|
||||
std::cout << " key2 value stored at: " << addressTable2.address() << std::endl;
|
||||
|
||||
// Check if key1 is still accessible
|
||||
std::cout << "3. Checking if key1 is still accessible..." << std::endl;
|
||||
try {
|
||||
int32_t val1 = table.get<int32_t>("key1");
|
||||
std::cout << " ✅ key1 still works: " << val1 << std::endl;
|
||||
} catch (const std::exception& e) {
|
||||
std::cout << " ❌ key1 broken: " << e.what() << std::endl;
|
||||
|
||||
// Let's see what's actually stored at key1's address
|
||||
try {
|
||||
auto ref = table.getReference("key1");
|
||||
std::cout << " key1 type is: " << static_cast<int>(ref.getType()) << std::endl;
|
||||
} catch (const std::exception& e2) {
|
||||
std::cout << " Can't even get type: " << e2.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\n=== Address Comparison ===\n" << std::endl;
|
||||
std::cout << "key1 address: " << addressTable1.address() << std::endl;
|
||||
std::cout << "key2 address: " << addressTable2.address() << std::endl;
|
||||
|
||||
if (addressTable1.address() == addressTable2.address()) {
|
||||
std::cout << "💥 SAME ADDRESS! This proves the bug!" << std::endl;
|
||||
} else {
|
||||
std::cout << "Addresses are different, issue is elsewhere" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user