How to find out how much memory the new operator allocated? Must be 200 bytes



11/6/2019 8:20:29 PM


11 Answers

New Answer


Find it out by using the sizeof operator and run. Different device gives different result so yeah, I can only find out using the sizeof


You don't. You have to keep track of this yourself. It is implementation defined where the compiler stores that information for the delete call. Unless the new call throws a bad_alloc exception and/or returns a nullptr you can be sure that it allocated at least the space you requested.


I'm not sure what the question was...


UraL I understand now.


UraL I think the only way is using 50*sizeof(*a) so the programmer has to keep track of the size of memory dynamically allocated in C.


👑Miss Solollearn Philippines (Storm Me) sizeof is not applicable in this case. give an example


Dennis ok


Sonic why? The question is concrete


use "sizeof()" function


Sumiya do it and show result:-)


Sumiya read above