Inqury Liberation Memory

Additional thanks to Daniel Newby for answering my memory usage question (and Martin York to explain this a bit more). This is definitely the answer I was looking for, but my other questions were satisfied by others.

Thank you all

to fix all my problems. It is very nice to see how everything works, as I expect them to work.

I came across something that I'm not quite sure about.

In my program I do not use malloc()or free(). I make copies of their classes new, and I'm sure that each of them runs it destructor, he delete'd , but no calls free()or even establishing their own indicators (for things in the global scope, or other classes) to NULLor 0.

What I mean by "I made sure" is not what I call every destructor. I use delete only to call the destructor to start, but I have variables that increment by 1 each time the object is created, and every time the destructor starts. This is how I made sure that the number of objects created is equal to the number of destructors called.

Should I use malloc()and free()in any case? Should I be NULLpointers to things that I still want to exist?

The second question: why, when I look at my task manager, my process never "falls" into memory? Previously, she never stopped gaining momentum, and then I started normally deleting. Or so I thought.

Will free()or deletereduce memory usage?

What methods should be used for malloc'ing and free' memory with linked lists?

0
source share
6 answers

malloc() free() ++. new delete. : NULL 0 ++ .

+2

delete new free malloc. delete , . - , , delete .

, , - . , , - ++: .

null , , . ++, "" , .. , ​​ .

p.s., .

edt: , , . , , boost.

+2

, malloc()/calloc()/realloc() free().

, std:: list. std::vector

: , .

0
  • new delete malloc ++ . , .. , , . malloc/free ++ /.

  • , , NULL , . , 0xdeadbeef, .

  • , "" , , . , , , " ", . , . , .

0

" malloc() free() ?"

, . . , malloc(), () , . , .

" free() delete ?"

, 4 . , . , , , . ( /, .)

0

malloc() free(). , , , 'd,

. - . (), (), , .

() ( ) NULL 0.

malloc/free ++- ( , C-, malloced memory, ).

NULL .
, . - (.. ) delete, NULL, .

malloc() free() ? NULLing , ?

.
: ++ Java , .
, , ( ).

: , , "" ? , . .

( ).
, ( ).
, . , , , , ( ).

free() delete ?

.

malloc'ing ?

, , .
.

But if you use pointers. call delete to delete the item, and then set the value to NULL (the pointer area is alive long after the delete call).

Note. Enhancement: shared_pointer is very similar to a Java pointer. It keeps track of the number of pointers and deletes the object when the last reference to the object is destroyed. You do not need to delete (like Java), and all you really need to do is call a new one (like Java).

0
source

Source: https://habr.com/ru/post/1735263/


All Articles