code: def address_of_memoryview(mv: memoryview) -> int:
      """
      Get the pointer to the first byte of a memoryview's data.
  
      If the memoryview is read-only, NumPy must be installed.
      """
      # NOTE: this method relies on pointer arithmetic to figure out
      # where each memoryview starts within the underlying buffer.
      # There's no direct API to get the address of a memoryview,
      # so we use a trick through ctypes and the buffer protocol:
      # https://mattgwwalker.wordpress.com/2020/10/15/address-of-a-buffer-in-python/
      try:
          carr = one_byte_carr.from_buffer(mv)
      except TypeError:
          # `mv` is read-only. `from_buffer` requires the buffer to be writeable.
          # See https://bugs.python.org/issue11427 for discussion.
          # This typically comes from `deserialize_bytes`, where `mv.obj` is an
          # immutable bytestring.
          pass
      else:
          return ctypes.addressof(carr)
  
      try:
          import numpy as np
      except ImportError:
          raise ValueError(
              f"Cannot get address of read-only memoryview {mv} since NumPy is not installed."
          )
  
      # NumPy doesn't mind read-only buffers. We could just use this method
      # for all cases, but it's nice to use the pure-Python method for the common
      # case of writeable buffers (created by TCP comms, for example).
      return np.asarray(mv).__array_interface__["data"][0]
  
file_path: distributed/distributed/protocol/utils.py
imports: from __future__ import annotations
  import ctypes
  import struct
  from collections.abc import Collection, Iterable, Sequence
  from typing import Literal, overload
  import dask
  from distributed.utils import nbytes
label_desc: Use image node_id 9 for calling a global function with example usage: address_of_memoryview(mv) and returns: np, ctypes