Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Tier 2: memset constructor

Author
Message
Kirkkaf17
6
Years of Service
User Offline
Joined: 3rd Jan 2018
Location:
Posted: 3rd Jan 2018 22:38
Hello all,

I have owned most of TGC products over the years and purchased AppGameKit not long after it's release but have yet to use it. I am a programmer by trade and decided to use go with tier 2. I was just going through the Offical Tier 2 Starters Guide and it suggested changing the constructor of the app class and remove the memset function as this can cause problems, but it doesn't go into detail of the problems it can cause, can anyone speak from experience here?



Cheers.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 4th Jan 2018 09:37 Edited at: 4th Jan 2018 09:46
This is just my opinion as I have not had a problem in Teir 2 but I have had a problem using memset on C++ compilers on embedded systems....

The constructor should set your initial class variable values and generally set up the class so you can use it.

Using the memset does this by setting the member variables to zero. The thing is you can never be sure of how the compiler works and exactly what it store in your app....Ie...if you implemented a virtual function within your class later on for whatever reason, it would also zero the values in a virtual function pointer table that is stored in the app class when it shouldn't do that.

Basically, write your constructor as you normally would in C++ and set up your class variables to whatever values they need to be 0, 1, 255 or whatever. The memset is a lazy way of doing that that on one line of code instead of carefully going through each variable and setting it properly. It wipes out all the values stored on the class, even those that the compiler might need.

Login to post a reply

Server time is: 2024-11-22 20:46:11
Your offset time is: 2024-11-22 20:46:11