5
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
Featured Replies
  • 1
    Narue 5,707   8 Years Ago

    >How can i delete a particular element using delete operator? Can you be more specific? A vague question produces vague answers, or completely off-the-wall answers as exhibited by the previous reply. Read More

0

Warning! O_O

Delete does not really delete!

Delete frees dynamically-requested memory that the C++ program obtained from the OS at run-time.

Delete does NOT actually delete anything! Do not use it freely, unless you really want to screw up your program or cause your OS to flag an error to whatever program attempted to tell the OS to unallocate memory that never belonged to the provoking application to begin with @_@.

1

>How can i delete a particular element using delete operator?
Can you be more specific? A vague question produces vague answers, or completely off-the-wall answers as exhibited by the previous reply.

Comments
Whoops, I took that literally X_X
0

Hi,

I am getting the following error :

test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called recursively
Abort trap

I am using finite recursion to build the nodes of binary tree. So i believe the C++ program should take care of the storage of nodes. I also think that it will store the nodes of the binary tree in a heap. So, i was thinking of trying to free some space during recursion using delete operator.

I am trying to free the memory corresponding to the second element of the 2 dimensional array.

Please help

Thanks

0

why are you using malloc() in a c++ program -- malloc() doesn't know how to allocate c++ objects? Use the new operator instead.

And you can not use the delete operator to free memory that was allocated by malloc(). delete only works with new.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.