Jump to content
  • Advertisement
Sign in to follow this  
Tonin

Object alignment

This topic is 4063 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

I've found that calling RegisterObjectType with a byteSize argument that is not a multiple of four causes an error. Is this alignment fixed, or is it variable on different platforms? Also, is it safe to pad the size argument up to the next multiple of four, or could that cause problems? I'd kind of like to avoid adding padding directly to the c++ classes if I can avoid it.. Thanks, ~Andy

Share this post


Link to post
Share on other sites
Advertisement
What compiler and target platform do you use?

I'll have to look into this as I'm not aware of any problems with bytes sizes non-multiple of four.

You should be able to pad the size the next multiple without any problem. The C++ compiler normally does this automatically when it allocates memory anyway, so telling AngelScript to also do this shouldn't be a problem.

Regards,
Andreas

Share this post


Link to post
Share on other sites
Hi, thanks for getting back to me, I'd given this thread up for dead [grin].

I'm using MSVC 2005 express edition on win XP home, with version 2.7.1b of angle script.

I looked into it a bit more after my first post and the compiler isn't padding classes that only hold chars (I don't know if that is the default or not. I don't think I changed any settings, but I could be wrong). Stepping through in the debugger I found a chunk in asCScriptEngine::RegisterObjectType that checks for size equal to 1, 2 or a multiple of four. I have been padding the sizes up with no problems so far, so it looks like that could be a workable solution.

~Andy

Share this post


Link to post
Share on other sites
Just a clue to your problem :

Microsoft compiler (since I use them VC5 ...) has always been packing the object's memory to 4 bytes (default value). See in project settings, C++ compiler options.

This padding can be overriden using a #pragma pack(n), where n is the byte alignment requested or by project setting.

Normaly, you use "#pragma push" and "#pragma pop" to push the compiler actual pack size and restore it to its setting.

If you include some .h files from other project than yours, there could be some #pragma pack(n) that are beeing used that you don't know about.

Hope it helps,

AbrKen.

Share this post


Link to post
Share on other sites
Sorry about the late response. I was on vacation, I had seen you're post before but didn't have the time to respond to it.

You're right, I had forgot about that validation. Actually, I can't remember anymore why I added that validation. Theoretically AngelScript shouldn't care about the size. I'll have to make some tests to see if it can be removed or what the reason for it is.

Regards,
Andreas

Share this post


Link to post
Share on other sites
No worries on the delay, it's not like this is a really major issue or anything.

Abrken, I did look into that but whatever pack pragma or /Zp options that are set, the compiler doesn't do any padding on classes that contain only chars. The sizeof() is always equal to the number of chars in the class declaration. I think it's probably the better part of valor to let it do its own thing in this case.

Thanks for the suggestion though!

~Andy

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!