-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stub implementation of new custom memory API #3437
base: main
Are you sure you want to change the base?
Conversation
93e52c4
to
90f16ac
Compare
90f16ac
to
4f574f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadly this is OK, and we should probably merge it as-is. Three minor points which we could address when we put the implementation in:
- I'm unclear why
bigarray.c
is so different between runtime 4 and runtime 5; - I would find this stuff easier to navigate with a clearer distinction in variable names and comments between custom block sizes and dependent memory sizes. Maybe consistently using
dep_size
? - Moar comments plzkthxbai.
reclaimed. | ||
*/ | ||
CAMLextern value caml_alloc_custom_dep(struct custom_operations * ops, | ||
uintnat size, /*size in bytes*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like a clearer distinction in the comments between size
and mem
.
@@ -251,7 +251,7 @@ caml_ba_alloc(int flags, int num_dims, void * data, intnat * dim) | |||
uses_resources = | |||
((flags & CAML_BA_MANAGED_MASK) == CAML_BA_MANAGED) | |||
&& !(flags & CAML_BA_SUBARRAY); | |||
res = caml_alloc_custom_mem(&caml_ba_ops, asize, uses_resources ? size : 0); | |||
res = caml_alloc_custom_dep(&caml_ba_ops, asize, uses_resources ? size : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear to me why this is different in runtime4.
CAMLexport value caml_alloc_custom_dep(const struct custom_operations * ops, | ||
uintnat size, mlsize_t mem) | ||
{ | ||
return caml_alloc_custom_mem(ops, size, mem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment indicating what else will go in here in future.
This is a stub implementation of @damiendoligez's new custom memory allocation API. The new API tracks both allocation and deallocation of dependent memory using
caml_alloc_dependent_mem / caml_free_dependent_mem
, and provides a convenience functioncaml_alloc_custom_dep
which combines a custom block allocation and a call tocaml_alloc_dependent_mem
.The difference from
caml_alloc_custom_mem
is that a user ofcaml_alloc_custom_dep
must be sure to callcaml_free_depedent_mem
when the custom block is finalised.In this PR, the new API is added so that we can port code to it, but under the hood it just calls
caml_alloc_custom_mem
and thealloc_dependent
/free_dependent
functions are no-ops.(The changes to the existing API functions
caml_alloc/free_dependent_mem
are not backwards compatible. However, I'm not aware of any actual users of these functions, and if we find one someday it's easy to adapt)