Are const vector references passed as argument allocated on the heap?

Viewed 65

Considering a function:

int f(
        const std::vector<int>& v1,
        const std::vector<int>& v2)
{
    int sum_1 = 0;
    for (int a: v1)
        sum_1 += a;
    int sum_2 = 0;
    for (int a: v2)
        sum_2 += a;
    return std::max(sum_1, sum_2);
}

When calling:

f({5, 7, 9}, {1, 2, 4, 3})

Are these vectors allocated on the heap? If yes, what would be a better design to avoid these allocations?

0 Answers
Related