% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/use_copy_on_modify.R
\name{use_copy_on_modify}
\alias{use_copy_on_modify}
\title{Adds the \code{CPPALLY_COPY_ON_MODIFY} flag to Makevars}
\usage{
use_copy_on_modify()
}
\value{
Invisibly adds the \code{CPPALLY_COPY_ON_MODIFY} flag to Makevars.
}
\description{
Adds a flag to Makevars which enables copy-on-modify behaviour like in R.
This ensures you can never modify object B's data by modifying object A
(unless you do it manually via \code{r_vec::data()}).

The default behaviour is that \code{r_vec::set()} always modifies-in-place with
no checks to shared or referenced objects. This default behaviour is
generally much faster.
\subsection{Parallelisation}{

Adding this global flag effectively kills most parallelisation.
To achieve copy-on-modify we have to check whether the \code{r_sexp}
object being modified is referenced anywhere else at each and every
call to \code{set()}. This check (via \code{r_sexp::is_exclusive()}) is not thread-safe
and therefore most cppally parallelisation is disabled
once CPPALLY_COPY_ON_MODIFY is set.
}
}
