Re:Drop millions of allocations by using a linked list (2015)
by thechao on Friday March 12, 2021 @09:17AM
(#26436038)
In the mid 00s, my advisor had me explore the concept of adding default parameters to C++ functions where the default snagged the nearest lexically scoped named object of the right type from the calling environment, i.e.,
int someFunctionThatAllocates(int A, int B, allocator const& alloc = default);
Then in the calling environments: {
auto& alloc = james;
if (someFunctionThatAllocates(4, 5)) // ok, uses 'alloc'
{
}
}
{
if (someFunctionThatAllocates(4, 5, james)) // ok, uses 'james'
{
}
}
{
auto& alloc1 = james;
if (someFunctionThatAllocates(4, 5)) // error: no `alloc` in scope
{
}
}
It handily solves a number of problems. In particular, we were looking at how we manage heap allocation for large sparse matrix libraries a la MTL4.
Re:Drop millions of allocations by using a linked list (2015)
by gpderetta on Friday March 12, 2021 @10:12AM
(#26436629)
Interesting. Isn't this this vaguely reminiscent of implicits in Scala?
This has a huge impact on the API design, so I don't think this can be retrofit in standard libraries of existing languages (because of backwards compatibility).