How much memory was actually allocated from heap for an object?

前端 未结 6 711
渐次进展
渐次进展 2020-12-30 17:09

I have a program that uses way too much memory for allocating numerous small objects on heap. So I would like to investigate into ways to optimize it. The program is compile

6条回答
  •  佛祖请我去吃肉
    2020-12-30 17:26

    [EDIT] This answer is wrong! I'm leaving it as an example of what not to do. The sizeof function operator works at compile time.


    Have you tried:

    SomeClass* some_instance = new SomeClass;
    printf("Size of SomeClass == %u", sizeof(*some_instance) );
    

    I seem to recall that by passing in an instance of a class you should get the size that was allocated.

提交回复
热议问题