Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. pin_ptr versus interior_ptr

pin_ptr versus interior_ptr

Scheduled Pinned Locked Moved Managed C++/CLI
question
3 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Schroedl
    wrote on last edited by
    #1

    I've used pin_ptr<> for years now but just came across interior_ptr<>. I supposed I may have been sheltered not needing it but can anyone illustrate why I'd prefer interior_ptr over pin_ptr? John

    J 1 Reply Last reply
    0
    • J John Schroedl

      I've used pin_ptr<> for years now but just came across interior_ptr<>. I supposed I may have been sheltered not needing it but can anyone illustrate why I'd prefer interior_ptr over pin_ptr? John

      J Offline
      J Offline
      Jon McKee
      wrote on last edited by
      #2

      A wee bit late but if you're still curious: interior_ptr is useful if you need pointer arithmetic in managed code or a pointer that can reference a managed or native object. It doesn't pin the referenced object and instead gets updated by the CLR when the object moves just like a handle. Can be useful for some functions that can operate on managed and native objects as a native pointer can be passed to an interior_ptr argument. pin_ptr is useful if you want a managed object that can be referenced by native code. It stops the GC from moving the object so the object's address can be safely assigned to a native pointer as long as the pin_ptr is alive. You see this used a lot when people manually marshal System::String to a char*. Cheers!

      J 1 Reply Last reply
      0
      • J Jon McKee

        A wee bit late but if you're still curious: interior_ptr is useful if you need pointer arithmetic in managed code or a pointer that can reference a managed or native object. It doesn't pin the referenced object and instead gets updated by the CLR when the object moves just like a handle. Can be useful for some functions that can operate on managed and native objects as a native pointer can be passed to an interior_ptr argument. pin_ptr is useful if you want a managed object that can be referenced by native code. It stops the GC from moving the object so the object's address can be safely assigned to a native pointer as long as the pin_ptr is alive. You see this used a lot when people manually marshal System::String to a char*. Cheers!

        J Offline
        J Offline
        John Schroedl
        wrote on last edited by
        #3

        Thanks Jon, It does help my understanding a lot! I didn't realize that interior_ptr could point to a managed or native object -- quite handy! John

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups