Skip to content

Commit a264965

Browse files
committed
mruby-os-memsize/memsize.c: fix irep size calculation
Need to count the following as well: - size of pool values - size of reps array
1 parent 1bc8ef9 commit a264965

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

mrbgems/mruby-os-memsize/src/memsize.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ static size_t
1616
os_memsize_of_irep(mrb_state* state, const struct mrb_irep *irep)
1717
{
1818
size_t size;
19-
int i;
2019

2120
size = (irep->slen * sizeof(mrb_sym)) +
22-
(irep->plen * sizeof(mrb_code)) +
23-
(irep->ilen * sizeof(mrb_code));
21+
(irep->plen * sizeof(mrb_pool_value)) +
22+
(irep->ilen * sizeof(mrb_code)) +
23+
(irep->rlen * sizeof(struct mrb_irep*));
2424

25-
for (i = 0; i < irep->rlen; i++) {
25+
for (int i = 0; i < irep->plen; i++) {
26+
const mrb_pool_value *p = &irep->pool[i];
27+
if ((p->tt & IREP_TT_NFLAG) == 0) { /* string pool value */
28+
size += (p->tt>>2);
29+
}
30+
else if (p->tt == IREP_TT_BIGINT) { /* bigint pool value */
31+
size += p->u.str[0];
32+
}
33+
}
34+
35+
for (int i = 0; i < irep->rlen; i++) {
36+
size += sizeof(struct mrb_irep); /* size of irep structure */
2637
size += os_memsize_of_irep(state, irep->reps[i]);
2738
}
2839
return size;

0 commit comments

Comments
 (0)