Comments (5)
Yes, a weak reference is basically what it is. I'll improve the documentation a bit regarding this.
from foundation_lib.
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.
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.
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.
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_t
s 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)
- Build errors on OSX/iOS HOT 13
- tests crash on VS2013 when building as debug and release HOT 7
- Typo HOT 1
- Loading library from relative directory doesn't work HOT 7
- Case insensible compare functions HOT 5
- Support for killing process HOT 4
- random32_range(0, 1) doesn't return 1 HOT 2
- Problems building foundation_lib using MSYS2 (MinGW) HOT 11
- What about closed/commercial project HOT 3
- build ? HOT 2
- Shared memory HOT 1
- Python3 compatibility HOT 6
- Lots of errors on Travis for macOS HOT 4
- Dead link HOT 1
- Thread Pool support HOT 1
- Consider remove PNaCl support HOT 6
- Why this library? Why C for game? HOT 2
- Maybe a bug in POSIX fs_is_file HOT 2
- CMake support? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foundation_lib.