Coder Social home page Coder Social logo

int vs int32 about go-sdl2 HOT 4 CLOSED

veandco avatar veandco commented on August 17, 2024 1
int vs int32

from go-sdl2.

Comments (4)

phicode avatar phicode commented on August 17, 2024

Golang's Int on 64 bit machines is 8 bytes.
Methods which return or accept an Integer could be changed easily.
Structures which are passed to SDL need to adhere to the ABI of the C structures.
Otherwise all structs would need to go through a translation layer.

I recently fixed (almost) all struct ABIs, see: https://github.com/veandco/go-sdl2/blob/master/sdl/struct_test.go

In general I agree that reducing type casts would be nice. On the other hand go ints do have different width on 32 and 64 bit systems.

from go-sdl2.

slevin avatar slevin commented on August 17, 2024

I see. I was mistakenly under the assumption that C ints would be 64bits on a 64bit machines. I missed that you were doing casting into and out of Go ints in parameters and return values. I guess translating structs would be too much a performance hit? And its not clear making everything int32 (parameters and return values) would be less casting or more convenient even if that might make the api more consistent.

from go-sdl2.

phicode avatar phicode commented on August 17, 2024

I contributed the unit tests and fixes because I ran into some misaligned structures while developing some little test applications.

From an architectural point of view I believe that a translation layer would make a lot of sense.
For example I did not fix the 'AudioCVT' structure because CGO has a hard time dealing with packed structures.

Since I only fixed existing code I did not add real struct translations (purely out of laziness :) )
My measurement so far have shown that crossing the barrier between C and GO through CGO is quite expensive. More than a very few thousand calls per frame is unrealistic.
So I believe that a translation layer would add few enough overhead to be noise against the CGO call overhead. Of course benchmarks would be required to verify this.

This could be a nice place to try out go:generate :)

@jackyb: Do you have any design in mind for this or similar issues?

from go-sdl2.

krux02 avatar krux02 commented on August 17, 2024

I actually would suggest, to chage the API to int whenever possible. For example in timer.go GetTicks and Delay could be changed to use int instead of uint32. For the Rect API, I do suggest, to implement both Rect and C compatible non exported rect32 for communication. I think a rectangle is small enough to be casted back and forth on calls, where it matters. All functions that do clipping and other calculations on rectangles should be ported to native go, to prevent CGO calls.

from go-sdl2.

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.