// unified_batch_box.c - Box U2: Batch Alloc Connector Implementation #include "unified_batch_box.h" #include "carve_push_box.h" #include "../box/tls_sll_box.h" #include // Batch allocate blocks from SuperSlab // Returns: Actual count allocated (0 = failed) int superslab_batch_alloc(int class_idx, void** blocks, int max_count) { if (!blocks || max_count <= 0) return 0; // Step 1: Carve N blocks from SuperSlab and push to TLS SLL // (uses existing Box C1 carve_push logic) uint32_t carved = box_carve_and_push_with_freelist(class_idx, (uint32_t)max_count); if (carved == 0) return 0; // Step 2: Pop carved blocks from TLS SLL into output array int got = 0; for (uint32_t i = 0; i < carved; i++) { void* base; if (!tls_sll_pop(class_idx, &base)) break; // Should not happen blocks[got++] = base; } return got; }