Jump to content
  • Advertisement
Sign in to follow this  
jeff8j

c++ class vs struct+functions

This topic is 1586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im writing a class with a little over 2000 functions associated with it they are pretty small but for this question im asking more in general rather than my use current use case.

 

Would a class having lots of functions in it occur more overhead than a struct+functions that do work on that struct? 

Share this post


Link to post
Share on other sites
Advertisement

lol well I know it probably not the right way of doing this but im making a x86-64 disassembler to c++/other languages and first it has alot of instruction codes then it will need to convert to a byte code then im shooting for c++ and javascript output c++ will be one thing but javascript is a completely different story.

 

I will do like swiftcoder mentioned and break it into different classes but just wanted to know what would happen with alot of functions in one class even say the disassembler to bytecode class will need a big switch and I was wanting to handle them in different functions so they can be over ridden and easily find able in a ide. I dont expect this to go anywhere just having my hand at learning more deeply about how everyting on the cpu gets done.

Share this post


Link to post
Share on other sites

lol well I know it probably not the right way of doing this but im making a x86-64 disassembler to c++/other languages and first it has alot of instruction codes then it will need to convert to a byte code then im shooting for c++ and javascript output c++ will be one thing but javascript is a completely different story.

 

I will do like swiftcoder mentioned and break it into different classes but just wanted to know what would happen with alot of functions in one class even say the disassembler to bytecode class will need a big switch and I was wanting to handle them in different functions so they can be over ridden and easily find able in a ide. I dont expect this to go anywhere just having my hand at learning more deeply about how everyting on the cpu gets done.

 

Considering all this, you may want to constantly reference a profiler for any future changes you make. Identify bottlenecks, evaluate if your code is too complex and figure out where you can make the code easier to read vs where you have to apply performance magic.

If you have to really go all out on a function to make it faster, you can put the old easy-to-understand version of the function in a comment, as sort of pseudo-code and go from there.

 

Some search words and references:

http://en.wikipedia.org/wiki/Branch_misprediction

http://www.ece.unm.edu/~jimp/611/slides/chap5_3.html

http://bigocheatsheet.com/

https://isocpp.org/wiki/faq/inline-functions

 

Ask if you need more specific help, eg with a function that is using too much time.

Edited by Kaptein

Share this post


Link to post
Share on other sites

So just as a reminder to the OP, but a struct is a class in C++, only difference is default visibility level, struct = public, class = private. If those functions are small, the compiler might just end up inlining most of the code anyway in a release build.

 

Still you should probably break this out a bit 2000 functions seems overkill for a class, although it could happen if you have a lot of one or two line functions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!