% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/memory.R
\name{estimate_memory}
\alias{estimate_memory}
\title{Estimate memory usage for a GWPR run}
\usage{
estimate_memory(context, workers = 1, cache_distance = NULL)
}
\arguments{
\item{context}{A `gwpr_context` list containing at least
\code{metadata$n_units}, \code{metadata$n_time}, and
\code{metadata$n_vars}.  If these keys are absent, the function falls
back to direct arguments \code{n_units}, \code{n_time}, and
\code{n_vars} when supplied via \code{...}.  Alternatively, pass a
plain list with the required scalar fields directly.}

\item{workers}{Positive integer.  Number of parallel workers.}

\item{cache_distance}{Logical or \code{NULL}.  When \code{TRUE} the full
\eqn{n\_units \times n\_units} distance matrix is assumed to be kept in
memory.  When \code{NULL} (default) the function assumes caching is
enabled for a conservative estimate.}
}
\value{
A named list with class \code{"gwpr_memory_estimate"}:
  \describe{
    \item{n_units}{Number of spatial units.}
    \item{n_time}{Number of time periods.}
    \item{n_vars}{Number of explanatory variables.}
    \item{n_rows}{Total panel rows (\code{n_units * n_time}).}
    \item{workers}{Workers used for the estimate.}
    \item{cache_distance}{Whether distance caching was assumed.}
    \item{distance_bytes}{Bytes for the distance matrix (0 if not cached).}
    \item{model_bytes}{Bytes for local model copies across workers.}
    \item{total_bytes}{Total estimated bytes.}
    \item{risk}{Character risk level: \code{"low"}, \code{"medium"}, or
      \code{"high"}.}
  }
}
\description{
Calculates an approximate memory requirement (in bytes) based on the
data dimensions stored in a `gwpr_context` object, the number of
parallel workers, and whether the full distance matrix will be cached.
}
\details{
The two main cost components are:
\itemize{
  \item Distance matrix (when \code{cache_distance = TRUE}):
        \eqn{n\_units^2 \times 8} bytes.
  \item Local model working copies (one per worker):
        \eqn{n\_rows \times n\_vars \times 8 \times workers} bytes.
}
}
\keyword{internal}
