Jolt's Allocate/Reallocate/Free/AlignedAllocate/AlignedFree go to libc's malloc with the size in a 16-byte header, and atomic counters keep live bytes, the peak and the blocks asked for (its job threads allocate too). The fence reads the three exports extern_weak to judge Jolt by its plateau. jolt_heap_test: a ground in and out 1100 times holds 46,482,514 bytes after the first 100 and after all of them, the peak does not move, and a closed world gives back every byte it took. The macOS library is rebuilt; the Windows DLL still has to be rebuilt on the PC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.5 KiB
Text
34 lines
1.5 KiB
Text
# jolt_heap_test.ludic - Jolt's own heap, counted in the shim (plan 25): a ground coming and going a
|
|
# thousand times holds what it held after the first hundred, and a world closed gives back what it took
|
|
import "ludic.physics"
|
|
import "ludic.base"
|
|
program JoltHeapTest {
|
|
numbers float
|
|
function cycle(physics_st: mut PhysicsState, h: []float, k: int) -> void {
|
|
let s = phys_heightfield(physics_st, h, 33, float(k % 7) * 64.0, 0.0, 2.0)
|
|
let b = phys_ground_add(physics_st, s)
|
|
phys_step(physics_st)
|
|
phys_remove(physics_st, b)
|
|
phys_shape_free(physics_st, s)
|
|
phys_settle(physics_st)
|
|
}
|
|
|
|
test "a ground in and out a thousand times holds Jolt's heap where it settled, and closing gives it back" (physics_st: mut PhysicsState) {
|
|
expect(phys_open(physics_st, 64, 1))
|
|
phys_close(physics_st)
|
|
let before = phys_heap_bytes() # the factory and the types, made once per process
|
|
expect(phys_open(physics_st, 64, 1))
|
|
expect(phys_heap_bytes() > before)
|
|
let h = floats(33 * 33)
|
|
for k in 0 .. 100 { cycle(physics_st, h, k) }
|
|
let held = phys_heap_bytes()
|
|
let peak = phys_heap_peak()
|
|
for k in 0 .. 1000 { cycle(physics_st, h, k) }
|
|
print(`jolt heap: {held} bytes held after 100 grounds, {phys_heap_bytes()} after 1100, peak {phys_heap_peak()}, {phys_heap_allocs()} blocks asked for`)
|
|
expect(phys_heap_bytes() == held)
|
|
expect(phys_heap_peak() == peak)
|
|
phys_close(physics_st)
|
|
print(`jolt heap: {before} bytes before the world, {phys_heap_bytes()} after it closed`)
|
|
expect(phys_heap_bytes() == before)
|
|
}
|
|
}
|