How to find out how much memory the new operator allocated? Must be 200 bytes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

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

https://code.sololearn.com/ciBC02Z1YjVl/?ref=app

6th Nov 2019, 8:20 PM
UraL
11 Answers
+ 11
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
7th Nov 2019, 2:27 AM
MCGAmedCoder gamerArtist
MCGAmedCoder gamerArtist - avatar
+ 8
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.
6th Nov 2019, 8:35 PM
Dennis
Dennis - avatar
+ 5
I'm not sure what the question was...
6th Nov 2019, 9:29 PM
Sonic
Sonic - avatar
+ 5
UraL I understand now.
6th Nov 2019, 10:49 PM
Sonic
Sonic - avatar
+ 5
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.
6th Nov 2019, 10:50 PM
Sonic
Sonic - avatar
+ 3
👑Miss Solollearn Philippines (Storm Me) sizeof is not applicable in this case. give an example
7th Nov 2019, 5:54 AM
UraL
+ 1
6th Nov 2019, 8:40 PM
UraL
+ 1
Sonic why? The question is concrete
6th Nov 2019, 10:47 PM
UraL
+ 1
use "sizeof()" function
8th Nov 2019, 12:56 PM
Sumiya
+ 1
Sumiya do it and show result:-)
8th Nov 2019, 5:26 PM
UraL
+ 1
Sumiya read above
8th Nov 2019, 5:26 PM
UraL