Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
hi to all.
What is the problem? why? :-?
 
std::vector<int>** indexes = new std::vector<int>*[8];
for(int i = 0; i < 8; i++)
{
    indexes[i] = new std::vector<int>[8];
}
 
//statments...

for(int i = 0; i < 8; i++)
{
    //problem is here !!!
    //Debug Assertion Failed!
    //expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
    delete indexes[i];
}
delete indexes;
Posted 2-Jan-13 22:50pm
Comments
Andreas Gieriet at 3-Jan-13 16:32pm
   
Having a variable of type std:vector<int>** look dubious.
I suggest to revisit your data type design.
Your immediate question is well answered by CPallini in Solution#2, but the root cause of your problem is probably your data type implementation as highlighted by H.Brydon in solution#4.
Cheers
Andi
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Quote:
delete indexes[i];

you forgot to delete[] on the array of objects, use:
delete [] indexes[i];
  Permalink  
Comments
__UFNHGGI_H__ at 3-Jan-13 5:19am
   
heeeeeeeeeeeeeeee.
thanks 1tera byte! :D
CPallini at 3-Jan-13 5:23am
   
You are welcome.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

In my opinion, already the allocation is wrong:
   indexes[i] = new std::vector<int>[8];
When I understand your code correctly, you want each cell indexes[i] to point to a std::vector. So it should be:
   indexes[i] = new std::vector<int>;
And of course, CPallini is right in that you should apply array brackets when finally deleting indexes. But this is not the problem that threw the assertion.
  Permalink  
v2
Comments
Philippe Mori at 3-Jan-13 22:01pm
   
Or maybe new std::vector<int>(8); if you want an array with an initial size of 8 elements.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Looks like you want a 2D array. I would suggest instead something like:
 
std::vector<std::vector<int>> indexes;
 
//statements...
 
and then you don't need to worry about the memory management. That is one of the main purposes of std::vector.
 
If you want a 3D array, then:
 
std::vector<std::vector<std::vector<int>>> indexes;
 
//statements...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 403
1 Sergey Alexandrovich Kryukov 227
2 Richard Deeming 180
3 ChauhanAjay 170
4 Snehasish_Nandy 161
0 Sergey Alexandrovich Kryukov 6,367
1 OriginalGriff 5,588
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100