In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days.
If you have to name the null pointer, call it nullptr; that's what it's called in C++11. Then, "nullptr" will be a keyword.
one last small question:
is delete(Blocks[a][b][c]) equivalent to Blocks[a][b][c] = 0
I'm currently using the latter.
As @Catfish666 said above; every new must have a corresponding delete. So if Blocks[a][b][c] is != NULL then you must delete and then assign NULL or 0 to it. Just assigning 0 to a valid pointer will not reclaim the memory allocated but merely lose the access to that memory!
delete is an operation that frees the memory allocated by new.
Assigning zero to a pointer doesn't free the memory.
Think of pointers like this: they are variables that store a number, which is a memory address.
When you use new, the new allocates memory and returns its address, address which you store in a pointer.
By setting the pointer to 0, you don't affect the memory that was allocated, instead you simply "forget" about it. And forgetting about allocated memory is bad in C++, because you are expected it to deallocate it yourself.
FWIW, manual deletion is error prone. If you want to use more modern C++ techniques, use a smart pointer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <memory> // <- for unique_ptr
typdef std::unique_ptr<Block> BlockPtr;
// Foo *Blocks[100][100][10000] = {0}; <- get rid of this
FooPtr Blocks[100][100][10000]; // <- replace with this
// allocate elements with this:
Blocks[a][b][c] = BlockPtr( new Block(...) );
// NO NEED to clean up.. .unique_ptr does it automatically
// no need to set to null after deleting... unique_ptr does it automatically
// no need to initialize to null prior to allocating... unique_ptr does it automatically
Though 100 * 100 * 10000 is an extremely large array and it's probably a very bad idea to have an array so large. Do you really need that many blocks allocated at once? I mean that is at least 95 MB of RAM in pointers alone.