GithubHelp home page GithubHelp logo

Struct packing with MSVC about libosmium HOT 14 CLOSED

osmcode avatar osmcode commented on July 23, 2024
Struct packing with MSVC

from libosmium.

Comments (14)

alex85k avatar alex85k commented on July 23, 2024

Yes, the error seems to vanish!
(however, you'll need to change initializer and getter/setter in a correct way)

from libosmium.

DennisOSRM avatar DennisOSRM commented on July 23, 2024

thanks for providing the bitfield packing link, @joto

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

The is a second alignment error:
D:\build_d\libosmium2\include\osmium/osm/changeset.hpp(307): error C2338: Class osmium::Changeset has wrong size to be aligned properly! [D:\build_d\libosmium2\build-cmake\examples\osmium_serdump.vcxproj]
Others seems to compile for now...

from libosmium.

joto avatar joto commented on July 23, 2024

I have committed a change that might fix this issue.

For the alignment error in changeset.hpp: Can you check adding string_size_type m_padding; after line 69?

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

I have committed a change that might fix this issue.

Yes, that helped!

For the alignment error in changeset.hpp: Can you check adding string_size_type m_padding; after line 69?

This time it do not help :)
https://github.com/alex85k/libosmium/tree/msvc-v3

from libosmium.

joto avatar joto commented on July 23, 2024

@alex85k: Can you somehow try to find out how the Changeset class is layed out? Maybe there is some kind of debugging option for the MSVC compiler to check.
All the internal fields should be uint32_t or int32_t, except the last one which is int16_t. Adding up the 8 bytes from class Item and 38 bytes from class Changeset should result in sizeof(Changeset) == 48 which it is with GCC and clang.

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

I'll try...

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

sizeof(osmium::Changeset) == 52. O_O
Investigating...

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

MinGW 64 bit:

sizeof(Item)             =8
sizeof(osmium::Timestamp)=4
sizeof(osmium::Timestamp)=4
sizeof(osmium::Box)      =16
sizeof(changeset_id_type)=4
sizeof(user_id_type )    =4
sizeof(string_size_type )=2
sizeof(num_changes_type) =4
sizeof(osmium::Changeset)=48

MSVC:

sizeof(Item)             =8
sizeof(osmium::Timestamp)=4
sizeof(osmium::Timestamp)=4
sizeof(osmium::Box)      =16
sizeof(changeset_id_type)=4
sizeof(user_id_type )    =4
sizeof(string_size_type )=2
sizeof(num_changes_type) =4
sizeof(osmium::Changeset)=52

Alignment...

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

Even setting field to static

    static osmium::Timestamp m_created_at;
        static osmium::Timestamp m_closed_at;
        static osmium::Box       m_bounds;
        static changeset_id_type m_id;
        static num_changes_type  m_num_changes;
        static user_id_type      m_uid;
        static string_size_type  m_user_size;

gives sizeof(osmium::Changeset)=12.

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

The reason: osmium::totally_ordered<Changeset> added 4 bytes!
Gr-r-r.. MS tricks us again!
http://social.msdn.microsoft.com/Forums/vstudio/en-US/504c6598-6076-4acf-96b6-e6acb475d302/vc-multiple-inheritance-empty-base-classes-bloats-object-size

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

And this:
http://stackoverflow.com/questions/12701469/why-empty-base-class-optimization-is-not-working

We'll have size increasing also for NodeRef, OsmObject, UnidirectedSegment...

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

I have added 4 bytes to Changeset to have at least 56 bytes (%8==0) instead of 48.
Do not know any better solution...

from libosmium.

alex85k avatar alex85k commented on July 23, 2024

Your solution is a little bit radical... But working :)

from libosmium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.