Like this ??Code:#include <cassert> ptr = new int[size] // dynamic allocate memory assert(ptr != 0) // terminate if memory not allocated
I'm reading a tutorial about c++ programming and it says "you should check the return value of every memory allocation". What does that mean?
Like this ??Code:#include <cassert> ptr = new int[size] // dynamic allocate memory assert(ptr != 0) // terminate if memory not allocated
Oh, I see. *I thought it had something to do with removing things from memory and then checking to see if the memor y was in fact freed.
no no, delete should remove all traces of the data.Oh, I see. I thought it had something to do with removing things from memory and then checking to see if the memor y was in fact freed.
So delete doesn't just remove the pointers to the memory and mark it free, it actually destroys the data?
Deleting the pointer is removing all traces, it's marked as usable space, to be overwritten.So delete doesn't just remove the pointers to the memory and mark it free, it actually destroys the data?
There is an easier way to say it than Lovechild (but he's not incorrect.)So delete doesn't just remove the pointers to the memory and mark it free, it actually destroys the data?
free()'d memory is not necessarily destroyed, that's compiler/OS dependent. In some cases, it may be destroyed, in others, it may merely be marked as unused. In the latter case, you could, if you really wanted to, keep using that data, but you can't rely on that data staying the same.
Is this how one would declared the variable [tt]ptr[/tt]?Like this ??Code:#include <cassert> ptr = new int[size] *// dynamic allocate memory assert(ptr != 0) * * * *// terminate if memory not allocated
Also, what is the difference between these two lines:Code:... int *ptr; ... ptr= new int[size]; ...
Code:myclass->mymethod(); (*myclass).mymethod();
I don't se any diffrence if it's the same as ansi c
there -> == (*variabel).(element)
Yes, that is the way to declare an int array, which is created with new, or you could use malloc() or calloc() or realloc() or alloca() any other memory allocating version.
Is this how one would declared the variable [tt]ptr[/tt]?
Code:... int *ptr; ... ptr= new int[size]; ...
This is playing with pointers, the derefferencing method with '->' is my favorit.Also, what is the difference between these two lines:
Code:myclass->mymethod(); (*myclass).mymethod();
Bookmarks