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

  • Home
  • SEARCH
  • 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 3362664
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:18:06+00:00 2026-05-18T03:18:06+00:00

If I want to call an external C++ function which returns a 2d array,

  • 0

If I want to call an external C++ function which returns a 2d array, what kind of problems could I come across? For instance, if I declare the 2D array inside of the C++ function and initialize the size of the array within the C++ function, how will the .Net automatic garbage collector handle this? Do I have to give it a function which performs garbage collection and if so how do I call it from a C# program?

  • 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-05-18T03:18:07+00:00Added an answer on May 18, 2026 at 3:18 am

    Unless the function returns a vector or vectors, it is the exact same problem in C++ as well. It is a memory management problem, the caller of the function has no good way to free the memory of the array, it doesn’t know the array sizes nor what allocator was used. For that matter, even iterating the array is perilous. A problem you can’t fix in C++ cannot be fixed in managed interop either.

    And you solve it the same way, you let the caller provide the array, to be filled by the callee.

    Note that managed arrays don’t have this problem, they are classes just like vector<>. Returning a managed array from a function is not an issue. C++/CLI can do it, the standard solution for difficult interop problems. A SAFEARRAY is also a solution, tell the P/Invoke marshaller about them with [MarshalAs] in the managed declaration.

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

Sidebar

Related Questions

I want to call a function (which calculates my version number) when my NSIS
I want to call a function from a .NET DLL (coded in C#) from
I want to call a c# function from my javascript function. I have a
The ShellExecuteEx Win32 function call has a flag SEE_MASK_FLAG_NO_UI in its SHELLEXECUTEINFO structure, which
I would like to call a method which could potentially take on different versions,
I want to call a web service, but I won't know the url till
I want to call a few static methods of a CPP class defined in
I want to call ShowDialog() when a keyboard hook event is triggered, but I'm
I want to call my .NET code from unmanaged C++. My process entrypoint is
I want to call some RESTful web services from a J2ME client running on

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.