Texture loading (without GLaux)

Currently i’m using an ANSI C compiler and get errors trying to assign the return value of the function “malloc” to a variable because it appears to be a ‘void’. Are there other ways to allocate memory for loading a texture image? Most of the examples/tutorials iv’e come accross use this method Eg.“memory=malloc(size);” for allocating texture image memory.

Right, malloc returns a pointer to a void. So you need to cast that void pointer to something else. E.g.:
unsigned char* mybuffer;
mybuffer=(unsigned char *)malloc(buffersize);

If you are using C++, you can simply use:
unsigned char *mybuffer=new unsigned char[buffersize];

Use C++ !
–> operator new
What’s better?

Great, thanks.
I’ve read about the “new” operator but i couldn’t figure out what the use of “malloc” was if one could use “new” instead. Would “delete” work as an alternative to “free()”?

[This message has been edited by Muerte (edited 10-11-2000).]

>Would “delete” work as an alternative to “free()”?<



Yes, if you allocate with new instead of malloc, you’ll have to use delete instead of free.
There’s one caveat : if you allocate an array with new[], i.e. x=new char[1000], you’ll have to free it using delete[], i.e. delete[] x. Otherwise the memory may not be correctly freed.