Understanding exactly when a data.table is a reference to (vs a copy of) another data.table

Yes, it’s subassignment in R using <- (or = or ->) that makes a copy of the whole object. You can trace that using tracemem(DT) and .Internal(inspect(DT)), as below. The data.table features := and set() assign by reference to whatever object they are passed. So if that object was previously copied (by a subassigning <- … Read more

What is the difference between a function call and function reference?

Well, the onclick property expects a reference to a function, for it to execute when the element is clicked. Normally it’s either: element.onclick = funcRef; or element.onclick = function () { funcRef(); }; (but of course, it’s best to use addEventListener and attachEvent) Notice how both of them are references to functions, not calling. When … Read more

How come a non-const reference cannot bind to a temporary object?

From this Visual C++ blog article about rvalue references: … C++ doesn’t want you to accidentally modify temporaries, but directly calling a non-const member function on a modifiable rvalue is explicit, so it’s allowed … Basically, you shouldn’t try to modify temporaries for the very reason that they are temporary objects and will die any … Read more

Why is it discouraged to accept a reference to a String (&String), Vec (&Vec), or Box (&Box) as a function argument?

TL;DR: One can instead use &str, &[T] or &T to allow for more generic code. One of the main reasons to use a String or a Vec is because they allow increasing or decreasing the capacity. However, when you accept an immutable reference, you cannot use any of those interesting methods on the Vec or … Read more