f_memcpy ======== Copy raw storage from ``src`` to ``dest``, with ``n`` counting source elements, without numerical or character-code conversion. .. code-block:: fortran use futile ! or: use f_memcpy_module, only: f_memcpy, f_memcpy_bytes Signature --------- Generated from the FYPP documentation stub ``doc/generated/f_memcpy_doc.f90`` (emitted by ``fypp/memcpy-doc.fypp`` from the same loops as ``flib/f_memcpy.f90``). In the signature, ``any_intrinsic`` is a documentation placeholder: the argument may be of any intrinsic type, of any Futile :ref:`ABI kind `. The supported combinations are listed under `Supported kinds and ranks`_. .. f:autointerface:: f_memcpy .. rubric:: Count inference when the count is omitted * Array source: copies the entire source payload. * Scalar source with array destination: fills the destination's byte capacity, which must be an exact multiple of the source element width. * Two scalar buffers: ``n`` is mandatory. Supported kinds and ranks ------------------------- The typed generic covers the concrete ``f_precisions`` ABI kinds (including complex and character) and ranks zero through seven: same type/kind arrays with equal ranks, scalar/array pairs, and rank-one/other-array pairs. Scalar/scalar starts accept all type/kind pairs. Other rank changes go through borrowed :doc:`f_subptr` views; unsupported combinations are rejected at compile time (no ``class(*)`` dispatch). .. fortran-specifics:: f_memcpy :args: dest, src Notes ----- .. rubric:: Capacity and bounds checks Known array capacities are checked in bytes before writing. Negative/excessive counts, an unrepresentable byte count, fractional inferred source elements and noncontiguous array sections raise ``ERR_INVALID_COPY`` without changing the destination. Zero-byte copies access neither data address; empty arrays copy zero elements. A zero-width scalar source cannot infer a count for a destination with nonzero byte capacity. .. rubric:: Overlap, contiguity and temporaries Partial overlap is supported through C ``memmove``. ``TARGET`` on the internal dummies permits ``C_LOC``; it does not guarantee that an arbitrary actual argument is passed without a temporary. Use contiguous variables, and actual array elements for scalar buffer starts. There is deliberately no ``CONTIGUOUS`` dummy attribute that would silently pack a strided section. .. rubric:: Ownership No allocation or ownership transfer occurs. When ``dest`` is a borrowed :doc:`f_subptr` view, writes modify the owner's storage. .. rubric:: Character data ``n`` counts complete source elements including each string's full length. Copying ``['ABC','DEF']`` from length-three elements into three length-two elements gives ``['AB','CD','EF']``: no padding or truncation, and a partial copy can end inside a destination element. For character codes use ``f_atoi``/``f_itoa`` or ``IACHAR``/``ACHAR`` explicitly; the former mixed character/integer overloads were removed. .. rubric:: Integer addresses An integer address value is itself an integer buffer, not an instruction to dereference that address. Examples -------- All examples are compiled and run by CI (``tests/flib/memcpy_check.f90``). .. tab-set:: .. tab-item:: Into a borrowed view .. fortranliteral:: tests/flib/memcpy_check.f90 :marker: subptr_copy :dedent: 4 .. tab-item:: Complex to real pairs One complex value into two reals (the storage transfer used by the complex DIIS path): .. fortranliteral:: tests/flib/memcpy_check.f90 :marker: complex_raw_copy See also -------- * :doc:`f_memcpy_bytes` -- copy between scalar buffer starts with an explicit **byte** count. * :doc:`f_subptr` -- borrowed rank-one views to adapt array ranks before copying. * :doc:`f_subptr_str` -- character-unit views when copying into or out of strings. * :doc:`f_size` / :doc:`f_sizeof` -- element counts and byte sizes for ``n``.