Skip to content

Commit

Permalink
Implement calculation of unmanaged size for CArray
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Mar 27, 2020
1 parent 8ed5e7f commit 48da6b2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/6model/reprs/CArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,21 @@ static MVMuint64 elems(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, voi
"Don't know how many elements a C array returned from a library");
}

static MVMuint64 unmanaged_size(MVMThreadContext *tc, MVMSTable *st, void *data) {
MVMCArrayREPRData *repr_data = (MVMCArrayREPRData *)st->REPR_data;
MVMCArrayBody *body = (MVMCArrayBody *)data;
MVMuint64 result = 0;

/* The allocated (or just-pointed-at) memory block */
result += body->allocated * repr_data->elem_size;

/* The array we hold wrapper objects in */
if (body->child_objs)
result += body->allocated * sizeof(MVMObject *);

return result;
}

static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) {
st->size = sizeof(MVMCArray);
}
Expand Down Expand Up @@ -519,6 +534,6 @@ static const MVMREPROps CArray_this_repr = {
NULL, /* spesh */
"CArray", /* name */
MVM_REPR_ID_MVMCArray,
NULL, /* unmanaged_size */
unmanaged_size, /* unmanaged_size */
NULL, /* describe_refs */
};

0 comments on commit 48da6b2

Please sign in to comment.