Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I suck at delete

Name: Anonymous 2008-10-22 15:48

So it seems I don't know how to use delete properly in C++. I have a "Matrix" class that dynamically allocates memory for a 2D array of floats, and I'm creating and destroying tonnes of these as the application runs. So I put this in the destructor.


for(GLuint i = 0 ; i < height ; i++)
  delete matrix[i];


It crashes instantly.

Here is the matrix variable:

GLfloat **matrix;


And here is the code setting up the matrix:

matrix = new GLfloat*[height];
for(GLuint i = 0 ; i < height ; i++){
  matrix[i] = new GLfloat[width];
  for(GLuint j = 0 ; j < width ; j++){
    matrix[i][j] = (i == j && isIdentity ? 1 : 0 );
  }
}


Wtf is my stupid ass doing wrong?

Name: Anonymous 2008-10-22 15:50

OK, first things first. Don't use OpenGL. It is shite.

Name: Anonymous 2008-10-22 15:52

Also you might as well keep your matrix as an array of 16 floats because that is how OpenGL does it.

Name: Anonymous 2008-10-22 15:53

It's shite NOW. ._.

Name: Anonymous 2008-10-22 15:54

I actually don't need more than 4x4 for this app, I just wanted to see if I could make a nice Matrix class and use it. So if it comes to that, yeah okay I'll make it 16x16 solid.

Name: Anonymous 2008-10-22 16:08

What?

I mean OpenGL represents its 4x4 matrices at a GLfloat array of 16 values.

Name: Anonymous 2008-10-22 16:11

Oh.. Heh. That did seem odd. :P

Well, regardless, this shit still crashes. So unless there's somethin immediately wrong with that code up there, I'm just gonna retreat back to no-dynamic town.

Name: Anonymous 2008-10-22 16:12

>>1
To answer your question, when you allocate with operator new[] you have to free with delete[]. It's one of the many esoteric pieces of shit that make Sepples a terrible language.

for(GLuint i = 0 ; i < height ; i++)
  delete[] matrix[i];
delete[] matrix;


Also, writing your own matrix operation is silly, especially if you're not SSE- optimizing them.

Name: Anonymous 2008-10-22 16:22

ONLY PUSSIES FREE MEMORY

THE OS FREES IT FASTER THAN YOU EVER CAN WHEN THE PROGRAM IS TERMINATED

JUST EXECVE A NEW INSTANCE IF YOU HAVE TO START FROM THE BEGINNING

ENJOY YOUR WASTED CPU CYCLES, I KNOW I WILL ENJOY THE EXTRA HEAT YOU GENERATE

Name: Anonymous 2008-10-22 16:22

Ah so there was a mistake there. Thanks. It does seem that the more I use "Sepples" the more I come to dislike it..

The app still crashes though, so fuck it, dynamic array is out.

Name: Anonymous 2008-10-22 16:30

>>10
Attach a debugger and find out why it crashes then.

Name: Anonymous 2008-10-22 16:32

>>10
1) Don't use quotes when you say Sepples
2) Yes, the farther you go the more you hate Sepples.

Name: Anonymous 2008-10-22 18:37


>>10
1) Programs always act the way the programmer told them to do, they don't have any ``mistake'' in THEM.
2) Don't learn OpenGL before knowing the basis
3) Doing something like new GLFloat[width][height]; is allowed in Sepples
4) I hope you realize you're assigning a boolean to a GLFloat without performing any typecast
5) See >>8,9
AND FUQIN LASTLY
isIdentity ? 1 : 0
THIS IS THE MOST USELESS PIECE OF CODE EVER WRITTEN


IHBT

Name: Anonymous 2008-10-22 19:10

>>13 here
I forgot to tell you I didn't mention anything about segfaults because if you've done what >>8 told you, there shouldn't be any, learn to debug the rest of your code by yourself now(start by finding out where it crashes)

Name: Anonymous 2008-10-22 19:23

Fuck sepples, use C.

I am not kidding.

Name: Anonymous 2008-10-22 21:07

Fuck C, use C++.

I am not kidding.

Name: Anonymous 2008-10-22 21:55

>>16
Yes you are.

Name: Anonymous 2008-10-22 23:05

Fuck GJS, use Julie.

I am not kidding.

Name: Anonymous 2008-10-23 6:02

new [] takes delete [] -- using plain delete is a heap corruption.

Since this is no longer 1990, why aren't you using boost::matrix?

Name: Anonymous 2008-10-23 6:32

>>19
Since this is no longer 1995, why aren't you using System.Collections.ArrayList?

Name: Anonymous 2008-10-24 12:05

>>18
I've never seen a picture of Julie.

Name: lol !8mQB/2odm6 2008-10-24 12:05

I'm going to email GJS and ask for a picture of Julie and a brief outline of her contributions to SICP.

Name: Anonymous 2008-10-24 12:14

>>22
Make sure you don't make us sound unscientific and ultimately destructive, this time.

Name: Anonymous 2008-10-24 14:13

>>22
Make sure you include a copy of your CV so that the Sussman knows you mean business.

Name: Anonymous 2008-10-25 11:54

>>23
Don't be a dick :(

He said your silly cult was unscientific and destructive, not the dolphin-linux-man.

Name: Anonymous 2011-02-03 3:01

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List