Common questions about Memory3D and their answers.
Memory3D is a sophisticated 3D virtual machine designed for efficient memory management with cryptographic verification capabilities. It extends traditional linear memory models into three dimensions (Regions, Planes, Offsets) for better spatial organization and features like Merkle tree proofs and gas metering.
Memory3D is suitable for:
- Systems requiring cryptographic memory proofs
- Applications with complex memory hierarchies
- Gas-metered execution environments
- Distributed systems needing memory verification
- Research in memory management architectures
Memory3D is at version 0.1.0. However, production use should include:
- Thorough testing in your environment
- Security review if handling sensitive data
- Performance benchmarking for your workload
- Monitoring and alerting setup
Maximum Addressable Space = 256 × 65,535 × 65,535 bytes
≈ 1.1 exabytes
Practical limits depend on:
- System RAM available
- Configuration settings
- Workload patternsgo get github.com/rawbytedev/memory3dGo 1.25.2 or later.
Only testify for testing. Core library has no external dependencies.
Yes, with appropriate testing and validation. See the Contributing Guide for development practices.
See Getting Started for a complete tutorial. Quick example:
config := vm.VMConfig{
MemorySize: 100 * 1024 * 1024, // 100MB
GasLimit: 10000000,
EnableProof: true,
}
vmInstance, _ := vm.NewVM3D(config)
defer vmInstance.Shutdown()- Allocate early: Pre-allocate memory blocks in initialization
- Use pools: Implement allocation pools for fixed-size blocks
- Clean up promptly: Always free memory when done
- Monitor fragmentation: Use compaction reports regularly
- Batch operations: Group allocations together
Typical operations:
Load 256 bytes: 10 + 512 = 522 gas
Store 256 bytes: 15 + 512 = 527 gas
Allocate 256 bytes: 20 + 256 = 276 gas
Free: 5 gas
Example workload (100 allocations + 100 stores + 100 loads):
≈ 27,600 + 52,700 + 52,200 = 132,500 gasNo, allocations are fixed-size. To resize:
// Old block
oldAddr, _ := vm.AllocateMemory(256, types.RegionTypeHeap)
vm.Store3D(oldAddr, oldData)
// New block (larger)
newAddr, _ := vm.AllocateMemory(512, types.RegionTypeHeap)
vm.Copy3D(oldAddr, newAddr, 256)
vm.Free3D(oldAddr)Address = [Region (X), Plane (Y), Offset (Z)]
[64-bit] [32-bit] [16-bit]
Example: Address3D{X: 0, Y: 0, Z: 0}
- Region 0, Plane 0, Byte 0
Each Region contains up to 65K Planes
Each Plane contains up to 64KB of dataPotential causes:
- High fragmentation: Check with
GetCompactionReport() - Gas calculations: Verify gas costs for your operations
- Lock contention: Check if multiple threads access VM
- Cache misses: Monitor spatial locality patterns
- Allocation strategy: Review allocation patterns
- Enable compaction: Set
EnableCompaction: true - Use larger blocks: Fewer allocations = better throughput
- Batch operations: Group reads/writes together
- Pool memory: Reuse allocated blocks
- Profile: Use
pprofto identify bottlenecks
Generation: ~500ns per address
Verification: Depends on proof path length, typically <10µs
Memory: ~32 bytes per leaf (SHA-256 hash)Only if you need cryptographic verification:
- Enable if: Need proof of memory state
- Disable if: Don't need verification (slight performance gain)
Region: Top-level memory container (256 max)
└── Plane: Sub-container holding actual data (65K per region)
└── Allocations: Individual memory blocksY-Promotion consolidates fragmented allocations:
Before: Plane 0: [A] [gap] [B] [gap] [C]
After: Plane 0: [gap] [gap] [gap] [gap] [gap]
Plane 1: [A][B][C][gap]...
Benefits: Better cache locality, fewer regions needed- Analyze: Scan for fragmented regions
- Plan: Identify allocations to move
- Execute: Move allocations to consolidated planes
- Refund: Return gas savings
Use AnalyzeCompaction() to preview without executing.
Yes, use compaction instruction:
inst := &vm.Instruction3D{
Opcode: vm.OP_MCOMPACT3D,
}
vm.ExecuteCompactInstruction(inst)Yes, with provisos:
- All public methods are thread-safe
- Uses RWMutex for synchronization
- Safe for concurrent reads
- Serialized writes
// Safe: Multiple goroutines can read
go func() { data, _ := vm.Load3D(addr, 256) }()
// Safe: Multiple goroutines can write (serialized)
go func() { vm.Store3D(addr, data) }()Yes, but writes are serialized internally. For true parallel execution, use multiple VMs:
vm1, _ := vm.NewVM3D(config) // Thread 1
vm2, _ := vm.NewVM3D(config) // Thread 2
// Each has own memory spaceMemory3D uses strict lock ordering:
- VM lock
- Region lock
- LRU lock
Locks are released before re-acquiring to prevent circular waits.
// Get detailed stats
stats := vm.GetStats()
fmt.Printf("Allocations: %d\n", stats.Allocations)
fmt.Printf("Memory usage: %d\n", stats.MemoryUsage)
// Get compaction report
report := vm.GetCompactionReport()
for _, r := range report {
fmt.Printf("Fragmentation: %.2f%%\n", r.Fragmentation*100)
}Each operation costs gas:
# Check remaining gas
remaining := vm.GetGasRemaining()
# Increase limit in config
config.GasLimit = 100000000 // Higher limitWrap errors with context:
if err != nil {
log.Printf("Operation failed: %v", err)
// Error message includes context
}Yes, region types affect allocation strategy:
addr1, _ := vm.AllocateMemory(256, types.RegionTypeHeap) // General
addr2, _ := vm.AllocateMemory(256, types.RegionTypeStack) // Stack
addr3, _ := vm.AllocateMemory(256, types.RegionTypeStatic) // StaticWith caveats:
- Validate input sizes before allocation
- Set reasonable gas limits
- Use separate VM instances per tenant
- Monitor execution time
// Validate before use
if userSize > MaxAllowedSize {
return fmt.Errorf("allocation too large")
}Merkle proofs provide:
- Integrity: Detect any tampering
- Authenticity: Verify state at specific point
- Non-repudiation: Prover can't deny later
Security depends on:
- Root hash publication/commitment
- Hash algorithm strength (SHA-256)
- Proof chain validation
Yes, gas costs are deterministic based on:
- Operation type
- Operation size
- Fixed overhead costs
Gas provides:
- Resource protection
- DoS attack prevention
- Fair resource allocation
# All tests
go test ./...
# Specific package
go test ./internal/allocator/...
# With coverage
go test -cover ./...
# Benchmarks
go test -bench=. ./test/benchmarks/...See Contributing Guide for full details:
- Fork repository
- Create feature branch
- Make changes with tests
- Submit pull request
- Respond to review feedback
Priority 3: Performance optimizations Priority 4: Extended instruction set Priority 5: External integrations
See Changelog for detailed roadmap.
- Check existing issues (no duplicates)
- Include:
- Steps to reproduce
- Expected behavior
- Actual behavior
- System info (OS, Go version)
- Attach minimal reproducible example
For security bugs, email
See API.md for comprehensive reference including:
- VM creation and configuration
- Memory operations
- Gas metering
- Merkle proofing
- Analysis functions
Most uses should go through the VM API. Low-level instruction execution:
inst := &vm.Instruction3D{
Opcode: vm.OP_MLOAD3D,
Operands: []vm.Operand{...},
Size: 20,
}
err := vm.executeInstruction(inst)Yes, by:
- Adding new opcodes
- Implementing execution functions
- Calculating appropriate gas costs
- Adding tests and documentation
See Contributing Guide.
Apache 2.0 License - see LICENSE file.
No patents on Memory3D core technology.
Yes, Apache 2.0 License permits commercial use. Just include license notice.
Still have questions?
- Open an Issue
- Check API Reference
- See Examples
- Read Architecture