|
From: Jason H. <jas...@bt...> - 2001-09-15 23:42:07
|
I'm afraid I can't offer you much help with OpenGL and those tutorials, =
but I do know something about "free()".
When programming in C you use free() allong with malloc() to dynamically =
create and *free* up memory. If you want to learn more about dynamic =
allocation you should read a good C/C++ book. Any C book should explain =
more about malloc() and free().
From what you have said it sounds like you need to include <stdlib.h>, =
which is where those functions are declared. If it is already defined =
then the problem is elsewhere.
As for alternatives... if you are using C++ (as aposed to pure C) then =
you can use the dynamic allocation functions that are part of the C++ =
language, which are new() and delete(). Again any good C++ book will =
explain these. Using malloc() and free() is still valid in C++ (and you =
can use the header <cstdlib> instead of <stdlib.h>), but new() and =
delete() are better because of the way they are designed to handle =
pointers and datatypes as part of the language.
i.e.
int *p;
p =3D new int[10]; // create an int array
for(int i=3D0; i<10; ++i)
p[i] =3D i*i; // fill array with square of 0 through to 9.
for(int i=3D0; i<10; ++i)
cout << p[i] << endl; // display contents of dynamic array.
// don't forget need to include <iostream> to use cout etc...
delete p; // always free up memory or you will get a memory leak!!!
...
This is just a quickie I created off the top of my head, so it probably =
won't work ;-) I'm too lazy to actualy test it.
p =3D new int[10];
is the same as
p =3D (int*) malloc(10*sizeof(int));
in C.
delete p;
is the same as
free(p);
in C.
Just remember you cannot use one malloc() with delete() and new() with =
free().... they don't mix.
Hope this helps, and anyone else feel free to point out any mistakes I =
may have made.
Jason.
----- Original Message -----=20
From: Joseph, Brandi, & Elise VanPelt=20
To: dev...@li...=20
Sent: Saturday, September 15, 2001 11:38 PM
Subject: [Dev-C++] Hello
Hello all,
This is my first post to this list. My name is Joseph, you can =
call me Blumojo (or "blu" or "mojo" for short). I really like Dev-cpp =
and am thinking of sending a donation if I can get the following to =
work. I am working on NeHe's OpenGL tutorials =
(http://nehe.gamedev.net/) which are really good - even for a novice =
like me, but the code he gave was for Visual CPP. I have worked through =
a couple of the problems, but have become "stumped" on lesson 7 where =
the compiler has given me:
"implicit declaration of function int free()"
In his explanation, this function is used to free memory used to store =
texture data.
First of all, has anyone worked through these tutorials and ported =
them to Dev-CPP/MinGW? If so, I would greatly appreciate the code to =
help me along. Second, is there another (perhaps better) way to free =
this memory?
Thank you all so much for the help!
-Bumojo
|