473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

deleting a multi-dimensional array

1
Hi!

I am having problem deleting a multi-dimensional array. I get the following error message: glibc detected ***double free or corruption (out). The program is below. I am following the steps in FAQ-Lite at: http://www.parashift.com/c++-faq-lit...tore-mgmt.html

Expand|Select|Wrap|Line Numbers
  1. void myarray (int sta1) {
  2.   double **sta_dist = new double*[sta1];
  3.   for (int = 0; i < sta1; i++) {
  4.     sta_dist[i] = new double [sta1];
  5.     for (int j=0; j < sta1; j++) {
  6.       sta_dist[i][j] = 0.0;
  7.     }
  8.   }
  9.  
  10.   if (sta_dist) {
  11.     for (int i = sta1; i > 0; --i) {
  12.       delete [] sta_dist[i-1];
  13.     }
  14.    delete [] sta_dist;
  15.   }
  16. }
Dec 4 '07 #1
1 1471
weaknessforcats
9,208 Expert Mod 8TB
if (sta_dist) {
for (int i = sta1; i > 0; --i) {
delete [] sta_dist[i-1];
}
delete [] sta_dist;
}
}
This doesn't look right. You need to delete from 0 through sta1:
Expand|Select|Wrap|Line Numbers
  1. if (sta_dist) {
  2.     for (int i = 0; i < sta1; ++i) {
  3.       delete [] sta_dist[i];
  4.     }
  5.    delete [] sta_dist;
  6.   }
  7. }
  8.  
Dec 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
4
by: Ken Bass | last post by:
Hi all, I have a client that is obsessed (actually paranoid) with security. One requirement he has is that any data deleted from a database be physically removed. This means not only within the...
5
by: Olaf Gschweng | last post by:
We're new into DB2 and have some problem with DB2 8.1 (?) on a Linux system. We load some big tables of a DB2 database from files every day. We do a "DELETE FROM table" for each table and then we...
1
by: dixie | last post by:
I am trying to adapt some code so that when I double click an entry in a multi-select list box, the entry represented by that entry is deleted from the table. The code I am trying sort of shows...
6
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application...
2
by: John | last post by:
Hi How can I do this programmatically; 1. Read the first file in a folder. 2. Search for its path+name in a field in a table. 3. If not found, delete the file in the folder.
8
by: JDT | last post by:
Hi, The last statement at the end of this post is to delete a set member 7.7. I set a break point inside ltstr::operator(). I found out that STL binary-seach the set twice. How come? I have...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
0
by: JudyK | last post by:
In Oracle, the most efficient way to delete a row (if using a cursor in SQL PL) is by rowid. Rowid is an internal unique identifier that Oracle assigns to every row in a database. So you would...
6
by: =?Utf-8?B?TU1TSkVE?= | last post by:
How to let user delete multi rows from the BindingSource while the SelectionMode Property set to RowHeaderSelect I have in my program datagridview bound it to sql table Throw Bindingsource To...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.