MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cr_scratch_get

Function cr_scratch_get

internal/cbm/result_compact.c:506–537  ·  view source on GitHub ↗

One zeroed block holding the slot table followed by the sequence. Returns * whether the block is the kept one (then the caller must not free it). */

Source from the content-addressed store, hash-verified

504/* One zeroed block holding the slot table followed by the sequence. Returns
505 * whether the block is the kept one (then the caller must not free it). */
506static bool cr_scratch_get(cr_ctx_t *c) {
507 size_t slot_bytes = c->cap * sizeof(cr_slot_t);
508 size_t bytes = slot_bytes + (c->refs * sizeof(uint32_t));
509 bool keep = bytes <= (size_t)CR_KEEP_BYTES && cbm_work_arena_keeping();
510 void *buf = NULL;
511 if (keep && tl_cr_buf && tl_cr_bytes >= bytes) {
512 buf = tl_cr_buf;
513 } else if (keep) {
514 size_t grown = CR_MIN_TABLE; /* powers of two: a growing file mix reallocates rarely */
515 while (grown < bytes) {
516 grown *= PAIR_LEN;
517 }
518 if (grown > (size_t)CR_KEEP_BYTES) {
519 grown = bytes;
520 }
521 cbm_result_compact_release_thread();
522 tl_cr_buf = cbm_alloc(CBM_MEM_CLASS_EXTRACT, grown);
523 tl_cr_bytes = tl_cr_buf ? grown : 0;
524 buf = tl_cr_buf;
525 } else {
526 buf = cbm_alloc(CBM_MEM_CLASS_EXTRACT, bytes);
527 }
528 if (!buf) {
529 return false;
530 }
531 memset(
532 buf, 0,
533 slot_bytes); /* MEASURE needs an empty table; the sequence is written before it is read */
534 c->slots = (cr_slot_t *)buf;
535 c->seq = c->refs ? (uint32_t *)((char *)buf + slot_bytes) : NULL;
536 return true;
537}
538
539static void cr_scratch_put(cr_ctx_t *c) {
540 if ((void *)c->slots != tl_cr_buf) {

Callers 1

cbm_result_compactFunction · 0.85

Calls 3

cbm_work_arena_keepingFunction · 0.85
cbm_allocFunction · 0.85

Tested by

no test coverage detected