0

Dynamic Memory Allocation operator

In C++: type *ptr, new, and delete are dynamic Memory allocation operator? Should we include delete too, since delete ob and delete[]ob are used to deallocate or freeing of allocated memory space.

4th Jun 2023, 3:20 AM
Oliver Pasaribu
7 Antworten
+ 2
This is really a semantics question rather than a code question, but I would say only new (of those) is doing any allocation, so just that one. If you're feeling masochistic, though, the old C options of malloc and calloc (and realloc) should also work in C++.
4th Jun 2023, 4:58 AM
Orin Cook
Orin Cook - avatar
0
Hello, pardon Orin Cook . This is not about "masochistic", you must know that now we are discussing computer science, coding. I just want to know, if delete is classified as dynamic Memory allocation too? In C we have malloc, calloc and realloc are also dynamic Memory allocation. But most people usually mention malloc and free.
4th Jun 2023, 10:37 AM
Oliver Pasaribu
0
Delete isn't any kind of allocation, so I would say no. It's closely related to dynamic allocation operations of course, but it's performing deallocation, not allocation. Pointers, likewise, are neither allocating nor deallocating anything; they're just pointing to it.
4th Jun 2023, 10:51 AM
Orin Cook
Orin Cook - avatar
0
This is about finding the real truth. Consider this problem: In c, malloc, int * ptr, and free is classified as a part of dynamic Memory allocation operator (it should include calloc and realloc I guess). If we generalize this situation, so new, and delete or delete[] are dynamic Memory operator in c++.
4th Jun 2023, 11:04 AM
Oliver Pasaribu
0
Like I said, this is a semantics question, not a code question. You can categorize them however is most useful for you. There is no such thing as "real truth" when it comes to semantics.
4th Jun 2023, 11:15 AM
Orin Cook
Orin Cook - avatar
0
Wrong. Semantically means that these words acome from ordinary English terminologi, so everything become easier now since we understand the meaning. In computer science learning, understand about the meaning of a word Will make the learning processes easier to manage, fun and interactive. Student are trained to think logically by their own self, this it minimize the dependencies to other entity as long as the literature or text book is ubiquitosly provided and can be easily understood. Ok?
4th Jun 2023, 11:25 AM
Oliver Pasaribu
0
Hard no, but this definitely isn't an appropriate forum for a deep dive into semiotics, so yeah sure whatever.
4th Jun 2023, 11:37 AM
Orin Cook
Orin Cook - avatar