Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using Qt and C++, I need to find out the amount of memory used by instances of certain Qt classes, this is usually done using sizeof, however in Qt each class holds a pointer to an another class containing the actual implementation, the definition of this private implementation class is not found in headers but only in the source-code.

I'm new to Qt so may be there's a standard way to do this, if there isn't do you have any ideas to solve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
147 views
Welcome To Ask or Share your Answers For Others

1 Answer

There is no way of doing this in Standard C++, and very few frameworks support anything like it. The reason is fairly simple - as you have observed, an object may contain pointers, and those pointers may point to further objects that contain pointers, and so on. And even when you get to the end of the pointer chain, there is no general method to find out how much memory a pointer points to.

So, you need to find another way to solve your problem, which I don't believe is the right problem to solve in the first place.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...