   difference between free(void) and delete
  my question is what dose delete do and what dose free() do, do both do the same thing or dose one open up a memory address while the other just leaves an address but no value stored in that address, i don't have a clue what the difference is uselly i only use free() for SDL_surfaces and delete for arrays or int but i have no clue why, any help would be appreciated thanks.   
  First thing to know: C++ is built upon C, which means it inherited (almost) all of it and ALL of its libraries.To allocate memory on the heap in C, you use the C library function malloc(). To free that memory, you use the function free().Now, in C++ you can still use malloc() and free(), BUT the preffered way is to allocate memory with the new operator and free it with delete. If you use C++, use new and delete.Keep in mind though, if you allocate memory with malloc(), free it with free(). That is, don't mix C and C++ here, you'll probably get in trouble.Oh and with SDL, there are function for freeing SDL_Surfaces. I think it's called SDL_FreeSurface().   ;  You must free what you malloc, delete what you new and delete[] what you new[]. I'm pretty sure freeing something that comes from an SDL call is wrong, and there probably is a function like SDL_release that you should use instead.Note that malloc and free are ONLY concerned with raw memory, whereas the C++ functions also construct and destruct objects.   ;  thank you, i always get confused with c stuff, is there a list somewhere of all the things like that there were replaced in c++, for example ifstream() and ofstream() instead of fopen().   ;Quote:Original post by ishkabiblethank you, i always get confused with c stuff, is there a list somewhere of all the things like that there were replaced in c++, for example ifstream() and ofstream() instead of fopen().C doesn't have classes, so everything that uses classes is C++ :) (ifstream, ofstrean, cout, cin).   ;  kk thank you very much.   ;  To confuse the issue further, there are operator new() and operator delete(), which are similar to, but incompatible with, malloc() and free().A new expression*, rather than a direct call to operator new, will involve a call to the same operator to obtain the memory, followed by the in-place construction of an object at that location. A simple delete expression will invoke the destructor, then it will release the memory using operator delete.The reason for this was that it was necessary to add something to C++ which allowed for dynamic (de)allocation of fully constructed objects, and this is how it was designed. Granted, the terminology can be confusing to a beginner.Finally, each library can (and often does) provide its own set of memory management functions (it can sometimes provide hooks so that you can )replace the allocation with your own functions, but this would be rather advanced. The reason for this is that free() is a simple function, it just releases a single allocation. However, some library objects will be complex, and destroying them might involve more than one deallocation.So, for SDL, any function which allocates memory generally has a corresponding function to release it. You need to check the documentation for this. The same will be true of most C libraries, and even some C++ ones. As an example, an SDL_Surface stores the pixel data separate from the bookeeping data, which describes the layout and format of the pixels. When you want to release a SDL_Surface, SDL_FreeSurface() will deallocate both. If you were using hardware surfaces, the deallocation might not involve free(), which complicates things again.This post is a little complex, but I hope it illustrates why we have so many allocation systems, rather than just how to handle it.* Well, a vanilla new expression. Things get complicated when using placement new or other overloads.   ;Quote:delete for arraysmalloc - freenew - deletenew[] - delete[]Last point is important - arrays are deleted with 'delete[]'   ;Quote:Original post by rip-offthere are operator new() and operator delete()You forgot operator new[]() and operator delete[]() ;-)   