// โญ Phase 10: Zero-copy Detection API Test // Test the new BufferBox zero-copy methods static box Main { init { console } main() { me.console = new ConsoleBox() me.console.log("๐Ÿงช Testing Zero-copy Detection APIs") // Test 1: Basic buffer creation and memory footprint local buffer1 = new BufferBox() local buffer2 = new BufferBox() me.console.log("Created two BufferBox instances") // Test memory footprint API local footprint1 = buffer1.memory_footprint() me.console.log("Buffer1 memory footprint: " + footprint1) // Test 2: is_shared_with() - should return false for independent buffers local shared_check1 = buffer1.is_shared_with(buffer2) me.console.log("Independent buffers shared: " + shared_check1) // Test 3: share_reference() - create shared buffer local shared_buffer = buffer1.share_reference(buffer2) me.console.log("Created shared reference") // Test 4: Check if shared buffer actually shares data with buffer1 local shared_check2 = buffer1.is_shared_with(shared_buffer) me.console.log("Shared buffer shares data with buffer1: " + shared_check2) // Test 5: Memory footprint should be similar for shared buffers local footprint_shared = shared_buffer.memory_footprint() me.console.log("Shared buffer memory footprint: " + footprint_shared) // Test 6: Write data and check sharing me.console.log("Writing data to test sharing...") // Create test data local test_data = new ArrayBox() test_data.push(72) // 'H' test_data.push(101) // 'e' test_data.push(108) // 'l' test_data.push(108) // 'l' test_data.push(111) // 'o' buffer1.write(test_data) me.console.log("Written test data to buffer1") local length1 = buffer1.length() me.console.log("Buffer1 length after write: " + length1) // Test 7: Check if shared buffer reflects the data local shared_length = shared_buffer.length() me.console.log("Shared buffer length: " + shared_length) if (length1.toString() == shared_length.toString()) { me.console.log("โœ… Zero-copy sharing working correctly!") } else { me.console.log("โŒ Zero-copy sharing failed") } me.console.log("๐ŸŽ‰ Zero-copy detection test complete") return "Test completed" } }