GithubHelp home page GithubHelp logo

Comments (5)

mjansson avatar mjansson commented on May 28, 2024 1

Yes, a weak reference is basically what it is. I'll improve the documentation a bit regarding this.

from foundation_lib.

mjansson avatar mjansson commented on May 28, 2024

The idea is that you can manage any kind of object, not only those that follow a reference counted object layout contract.

Regarding task_lib, the idea there is that the libs should remain separate and task_lib depend on foundation_lib, to avoid this base library of growing into a kitchen sink.

from foundation_lib.

ChengCat avatar ChengCat commented on May 28, 2024

Thanks for the explanation! That makes sense.

Regarding task_lib, I thought it is fundamental enough to be merged into foundation_lib, and it seems that you did the same with timer_lib. It is definitely acceptable to leave task_lib as a separate library though. :)

from foundation_lib.

mjansson avatar mjansson commented on May 28, 2024

Raw pointers with reference count in the target memory area also suffers from intrinsic thread unsafety. To check if the pointer is valid by looking at the reference count, you need to access the memory area, potentially causing a segfault if it has been freed.

With the object map and indirect "handles", you always increase reference when accessing the raw pointer through objectmap_acquire and you can be sure it is valid until you release the access with a call to objectmap_release, all in a thread safe way. The lifetime of the raw pointer becomes well defined.

from foundation_lib.

ChengCat avatar ChengCat commented on May 28, 2024

Thanks for the further explanation!

To check if the pointer is valid by looking at the reference count, you need to access the memory area, potentially causing a segfault if it has been freed.

I don't think this is how reference counting usually works. A programmer should be sure that at least one reference count is acquired before doing any operation on the object, including checking the current reference count.

objectmap however makes weak references possible. All object_ts can be seen as weak references, and the number of strong references to the object (i.e. reference count) are manipulated explicitly with objectmap_acquire and objectmap_release. This is done at the expense of an indirect memory lookup. I'd say it's an interesting design, and has its trade-offs.

I have found foundation_lib to have some other interesting and unusual designs. For example, condition variable is merged into mutex, and each mutex has a string name. I'd definitely try them out in my game. :)

from foundation_lib.

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.