Easier/streamlined referencing
Frityet opened this issue · 1 comments
Frityet commented
Right now, it is not exactly clear when or how to pass references
void use_reference(int *ptr)
{
//do I reference here?
auto int *ref = mc_reference(ptr);
}
int main()
{
auto int *ptr = mc_managed_alloc(sizeof(int), 1, NULL);
//or here?
use_reference(mc_reference(ptr));
}
Although this is up to the programmer to decide, it would still be useful to have a standard/safer way to do this, to avoid forgetting to call mc_reference
.
The top example would probably work the best, as with the second method you have to manually call release
in the use_reference
function to release the reference, unless you store the reference into a new pointer like so
void use_reference(int *ptr)
{
auto int *ref = ptr;
}
int main()
{
int *ptr = mc_managed_alloc(sizeof(int), 1, NULL);
use_reference(mc_reference(ptr));
}
Frityet commented
void use_reference(int *ptr)
{
auto int *ref = ptr;
}
int main()
{
int *ptr = mc_managed_alloc(sizeof(int), 1, NULL);
use_reference(mc_reference(ptr));
}
This seems to be the most stable method, and should be considered as the best way