Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:20:39+00:00 2026-06-18T10:20:39+00:00

In managed/unmanaged array interoperability, I have a case of not having the usual fixed

  • 0

In managed/unmanaged array interoperability, I have a case of not having the usual

fixed (byte* data = new byte[length])
{
    // work with the array
}

but rather, I want to pin an array where I only get a reference, like this:

IntPtr dataPtr = camera.Image2d.GetDataBuffer();
fixed (byte* data = (byte *)dataPtr)
{
   // work with the array
}

1) From my understanding, the bottom code should also work, since ‘fixed’ will pin a memory location low level in the memory manager, and not care about any objects pointing to it? (Meaning, I do not have the “root”/a direct pointer – even though there probably is not any such concept.)

One additional question:

2) The requirement to use ‘fixed’ comes from the CLR memory manager running concurrently to any executed code, thus it could move arrays at any time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:20:41+00:00Added an answer on June 18, 2026 at 10:20 am

    1) the second one does not seem proper as using the fixed keyword you are trying to pin the pointer, not the actual object. And IntPtr is not even (afaik) a managed pointer, rather an unmanaged one.

    2) fixed creates a pointer to the specified managed variable; and without pinning, GC may relocate the variable to another memory location, thus pointer will become useless.

    from msdn:

    The fixed statement sets a pointer to a managed variable and “pins”
    that variable during the execution of the statement. Without fixed,
    pointers to movable managed variables would be of little use since
    garbage collection could relocate the variables unpredictably. The C#
    compiler only lets you assign a pointer to a managed variable in a
    fixed statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have a struct that it's data is provided by un-managed byte array
I need to read unmanaged memory into a managed byte array. For this I
I have a managed C++ class, with a method whose constructor signature is: tools_package_net::PackageInfo::PackageInfo(array<Byte>^
I'm having a problem with mixing managed and unmanaged code. I have created two
I have a simple managed C++ assembly which I am providing unmanaged wrappers for
I have a situation in which a managed DLL calls some unmanaged DLL. I
My wrapper from managed to unmanaged is handling a lot of data and this
I have existing managed and unmanaged software using an ActiveX component supplied by a
I wanted to convert array< Byte>^ to unsigned char*. I have tried to explain
I have an unmanaged class, which I'm calling from a C++ Windows Form (managed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.