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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:50:09+00:00 2026-06-02T02:50:09+00:00

As an intro, I’m using C++ in Visual Studio 2010, compiling for x64. I

  • 0

As an intro, I’m using C++ in Visual Studio 2010, compiling for x64. I have a program that’s using 2-Dimensional arrays to store data for running through a C style function that I have no control over:

float **results;
results = new float*[rows];
for (int i = 0; i < rows; ++i){
    results[i] = new float[columns];
}

int **data;
data = new int*[rows];
for (int i = 0; i < rows; ++i){
    data[i] = new int[columns];
}

//send data to the function and populate results with values
ExternalFunction(*data, *results);

//delete everything
for (int i = 0; i < rows-1; ++i){
    delete [] &results[i];
    delete [] &data[i];
}
delete [] results;
delete [] data;

This causes VS10 to through a Debug Assertion Failure with _BLOCK_TYPE_IS_VALID(pHead -> nBlockUse). This happens by the end of the program regardless of what really happens in the last few lines containing the deletes. What does this mean exactly? What am I doing wrong? I feel like it’s really simple, but I’ve been looking at this code for too long.

–EDIT—
Problem solved thanks to dasblinkenlight’s helpful nudge to my brain!

float *results = new float[rows * columns];
float *data = new float[rows * columns];

ExternalFunction(&data[0], &results[0]);

delete [] results;
delete [] data;
  • 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-02T02:50:12+00:00Added an answer on June 2, 2026 at 2:50 am

    Your code crashes because you are passing an address of an address to delete[], which is not what you allocated. Change your code to this:

    for (int i = 0; i < rows ; ++i){
        delete [] results[i];
        delete [] data[i];
    }
    

    It will no longer crash.

    The rule on this is simple: since you assigned the results of new[..] to results[i], you should be passing results[i], not &results[i], to delete []. Same goes for data.

    Also note that this code deletes all rows that you allocated, including the last one (the loop condition is now i < n, not i < n-1). Thanks bjhend!

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

Sidebar

Related Questions

Intro I have an object @organization that has_many :quick_facts Basically, I want to produce
INTRO: I created a java application using JFrame. I have a JMenuBar at the
INTRO I have a TCP/HTTP server that supports plugins in form of Shared Libraries
I have an 'intro' page that I am creating and I want to click
This is part of a matlab intro course for biologists. I have my data
Intro I work in a facility where we have microscopes. These guys can be
Intro: EDIT: See solution at the bottom of this question (c++) I have a
Intro: Web application, ASP.NET MVC 3, a controller action that accepts an instance of
Brief intro about my requirement. I have an empty JSF dataTable. Now, when I
Content type Events has intro, body and an event date field (using Date module).

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.