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. C#
  4. Create a managed array from a pointer?

Create a managed array from a pointer?

Scheduled Pinned Locked Moved C#
data-structuresperformancequestionlounge
3 Posts 2 Posters 0 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
    Josh Martin
    wrote on last edited by
    #1

    Is there a way to create a managed array from a pointer to a block of unmanaged memory? I need to allocate a bunch of memory outside of the garbage collector, but I also need to access it through a managed byte array. Is this even possible? Right now, I'm creating the managed array and using a pointer to the first element, but this has a random habit of breaking when the garbage collector decides to move the managed memory around :~. Updating the pointer to the new location isn't really an option, as the pointer is being passed to an unmanaged DLL (which blows up when the GC moves the memory X|). Josh Find a penny, pick it up, and all day long you'll have a back-ache...

    J 1 Reply Last reply
    0
    • J Josh Martin

      Is there a way to create a managed array from a pointer to a block of unmanaged memory? I need to allocate a bunch of memory outside of the garbage collector, but I also need to access it through a managed byte array. Is this even possible? Right now, I'm creating the managed array and using a pointer to the first element, but this has a random habit of breaking when the garbage collector decides to move the managed memory around :~. Updating the pointer to the new location isn't really an option, as the pointer is being passed to an unmanaged DLL (which blows up when the GC moves the memory X|). Josh Find a penny, pick it up, and all day long you'll have a back-ache...

      J Offline
      J Offline
      Jim Stewart
      wrote on last edited by
      #2

      Try this[^] and this[^].

      α.γεεκ

      Fortune passes everywhere.
      Duke Leto Atreides

      J 1 Reply Last reply
      0
      • J Jim Stewart

        Try this[^] and this[^].

        α.γεεκ

        Fortune passes everywhere.
        Duke Leto Atreides

        J Offline
        J Offline
        Josh Martin
        wrote on last edited by
        #3

        Thanks for the links. I'd already read the article on pointers, but missed the article on arrays. Unfortunately, I didn't see anything in the array article that would help me create a managed array reference to an unmanaged memory block. I'll just have to think harder, I guess. Josh Find a penny, pick it up, and all day long you'll have a back-ache...

        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