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 5952061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:37:39+00:00 2026-05-22T17:37:39+00:00

Hey there, assuming I have the following code in a mex routine: mxArray *newPoint

  • 0

Hey there,
assuming I have the following code in a mex routine:

mxArray *newPoint = mxDuplicateArray(prhs[0]);
double *newPointData = mxGetPr(newPoint);
newPoint = mxDuplicateArray(prhs[1]);

do I have than to update newPointData also again to point to the new mxArray? And what about the memory where the first occurance of newPoint points to? Do I than also need to destroy that via mxDestroyArray(newPoint); because if I don’t do it, I’ll loose the address to it after re-assigning newPoint.

Thanks!

Edit: Bump on this please for a better understanding of memory allocation problem!?

  • 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-22T17:37:40+00:00Added an answer on May 22, 2026 at 5:37 pm

    mxDuplicateArray allocates a new array and copies the data. Each new duplicated array will have its data stored in a different memory region.

    So, yes, you have to use mxGetPr() to get the address of the data after each call to mxDuplicateArray().

    And naturally, allocated arrays must be deallocated. For that, you need to keep the original pointer to each mxArray created (the one returned by mxDuplicateArray).

    Finally, you cannot destroy the mxArray after taking the address of the data (using mxGetPr). Otherwise you are accessing memory which has been deallocated and may be allocated again by other code for a different purpose.

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

Sidebar

Related Questions

Hey there, I'm trying to make a site which have following: News, Products, About
I have the following JSON: { @id: hey there, id: hey there 2 }
Hey, in the Programming Pearls book, there is a source code for setting, clearing
Hey there I got a problem with my code, I compared three ways of
Hey there guys and gals. I'm very new to php and am following various
hey there i am having problem i have List<List<memoryCard>> that i want to show
Hey there, I've got a block of HTML that I'm going to be using
Hey I was wondering if there were any way to upload images in ASP?
Hey, is there any built in functions or something like that in php that
lets say i have a tree of the following structure: <div>node level1 <div>node level2

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.