News for hackers. Stuff that matters.
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?
Re:Drop millions of allocations by using a linked list (2015) by thechao on Friday March 12, 2021 @06:04PM (#26442033)
Yep; Martin suggested it to us; he said the ergonomics were good.
Re:Drop millions of allocations by using a linked list (2015) by injidup on Friday March 12, 2021 @12:59PM (#26438681)
It's called implicits in Scala