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

Function record_alloc

src/foundation/mem_events.c:1022–1075  ·  view source on GitHub ↗

── events ───────────────────────────────────────────────────────────*/

Source from the content-addressed store, hash-verified

1020
1021/* ── events ───────────────────────────────────────────────────────────*/
1022static void record_alloc(tl_state_t *st, uintptr_t block, size_t requested, size_t usable,
1023 uintptr_t site, int mem_class, unsigned flags) {
1024 st->ops++;
1025 uint32_t sid = site_index(site);
1026 if (sid == MEMEV_NO_INDEX) {
1027 st->site_table_full++;
1028 return;
1029 }
1030 uint64_t charged = usable ? usable : requested;
1031 st->alloc_seq = (st->alloc_seq + 1) & (uint32_t)MEMEV_SEQ_MASK;
1032
1033 bool zeroed = (flags & CBM_MEMEV_ZEROED) != 0;
1034 bool filled = false;
1035 if (!zeroed && !(flags & (CBM_MEMEV_FOREIGN | CBM_MEMEV_WRITTEN)) &&
1036 charged <= MEMEV_FILL_CAP && fill_enabled()) {
1037 memset((void *)block, MEMEV_FILL_BYTE, (size_t)charged);
1038 filled = true;
1039 }
1040
1041 shard_t *sh = shard_of(block);
1042 lock_take(&sh->lock);
1043 ptr_entry_t *e = shard_insert(sh, block);
1044 if (e) {
1045 e->usable = charged;
1046 e->requested = requested;
1047 e->seq = (st->slot << MEMEV_SEQ_BITS) | st->alloc_seq;
1048 e->site = (uint16_t)sid;
1049 e->mem_class = (int8_t)mem_class;
1050 e->meta =
1051 (uint8_t)((atomic_load_explicit(&g_phase, memory_order_relaxed) & META_PHASE_MASK) |
1052 (filled ? META_FILLED : 0) | (zeroed ? META_ZEROED : 0));
1053 }
1054 lock_drop(&sh->lock);
1055 if (!e) {
1056 st->pointer_table_full++;
1057 }
1058
1059 site_counters_t *c = tl_site(st, sid);
1060 c->allocs++;
1061 c->requested_bytes += requested;
1062 c->usable_bytes += charged;
1063 if (mem_class == CBM_MEMEV_CLASS_RAW) {
1064 c->raw_bytes += charged;
1065 }
1066 if (e) {
1067 c->live_bytes += (int64_t)charged;
1068 c->live_blocks++;
1069#if defined(CBM_MEMWASTE_ACCESS) && CBM_MEMWASTE_ACCESS
1070 if (!(flags & (CBM_MEMEV_FOREIGN | CBM_MEMEV_LIBRARY))) {
1071 acc_track(st, block, charged, sid, zeroed, filled, (flags & CBM_MEMEV_WRITTEN) != 0);
1072 }
1073#endif
1074 }
1075}
1076
1077void cbm_memev_alloc_ex(void *block, size_t requested, size_t usable, void *site, unsigned flags) {
1078 if (!cbm_memev_enabled()) {

Callers 2

cbm_memev_alloc_exFunction · 0.85
cbm_memev_reallocFunction · 0.85

Calls 8

site_indexFunction · 0.85
fill_enabledFunction · 0.85
shard_ofFunction · 0.85
lock_takeFunction · 0.85
shard_insertFunction · 0.85
lock_dropFunction · 0.85
tl_siteFunction · 0.85
acc_trackFunction · 0.85

Tested by

no test coverage detected