Giter Club home page Giter Club logo

Comments (4)

slouken avatar slouken commented on September 13, 2024 1

We could definitely make the pending-deletion list a thread-local thing, which will free everything if that thread pumps the event queue, or the thread terminates, but we chose the event queue because a) we already had something in place for dynamic event memory and b) every app (should) reliably call this function at a regular interval so the app wouldn't have to do anything new. But there's no reason we can't offer a way for a long-running thread that doesn't pump the event queue to clean the list out from time to time.

That's actually not a bad idea. That guarantees that the memory is thread-safe, and we can expose SDL_FlushEventMemory(0) as SDL_TrimThreadMemory() or SDL_GiveMyMemoryBackYouPeskyStringRule() or something. :)

from sdl.

slouken avatar slouken commented on September 13, 2024

This was the original reason we weren't going to go with this approach for SDL strings. I know we had some different ideas that all had drawbacks. @icculus, what was the final solution we landed on?

from sdl.

icculus avatar icculus commented on September 13, 2024

Hmm, the current documentation says the pointer is safe until the event queue runs from any thread, but yeah, that would be a surprising result for most people.

SDL_FreeLater() holds the event lock, so you can't lose a pointer to a race condition if the main thread is in the middle of running the event queue when it happens. Anything after that just makes the race after different, if the main thread is just calling the event queue in a tight loop: do we require the memory to live at least X milliseconds, or event pumps, before it's eligible? If the background thread gets hung up for a bit, still trouble,

Let me think on this a bit.

from sdl.

icculus avatar icculus commented on September 13, 2024

We could definitely make the pending-deletion list a thread-local thing, which will free everything if that thread pumps the event queue, or the thread terminates, but we chose the event queue because a) we already had something in place for dynamic event memory and b) every app (should) reliably call this function at a regular interval so the app wouldn't have to do anything new. But there's no reason we can't offer a way for a long-running thread that doesn't pump the event queue to clean the list out from time to time.

from sdl.

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.