HackerTrans
TopNewTrendsCommentsPastAskShowJobs

niekb

no profile record

Submissions

PAC Privacy: practical alternative to differential privacy

techblog.rosemanlabs.com
3 points·by niekb·8 เดือนที่ผ่านมา·0 comments

A safe, non-owning C++ pointer class

techblog.rosemanlabs.com
49 points·by niekb·10 เดือนที่ผ่านมา·47 comments

comments

niekb
·10 เดือนที่ผ่านมา·discuss
> isn't everything multi-threaded these days..

There are alternative ways to utilize a machine with multiple cores, e.g. by running one thread per CPU core, and not sharing state between those threads; in each such thread you then have single-thread "semantics".
niekb
·10 เดือนที่ผ่านมา·discuss
That was mostly meant as irony/a joke, but I admit that's not really clear from the text... For the sake of clarity, if you need thread-safety, probably best to just use std::shared_ptr / std::weak_ptr.
niekb
·10 เดือนที่ผ่านมา·discuss
(Author here.) That is a good question. For our use case, we in fact do not use std::shared_ptr in our implementation, but instead a single-threaded shared_ptr-like class that has no atomics (to avoid cross-core contention). However, when I wrote the blog-post, I replaced that not-so-well-known class by std::shared_ptr for the sake of accessibility of the blogpost for a general c++ audience, but by doing so, it indeed becomes a natural question to ask why one wouldn't use std::weak_ptr (which I hadn't realised when writing the post).

One reason why this design can still be beneficial when using the standard std::shared_ptr in its implementation, is when you do not want to manage the pointee object by a std::shared_ptr (which is a requirement if you want to use std::weak_ptr). E.g., if you want to ensure that multiple objects of that type are laid out next to each other in memory, instead of scattered around the heap.

Another goal of the post is to show this idea, namely to use a shared_ptr<T*> (instead of shared_ptr<T>), which is kind of non-standard, but can be (as I hope I convinced you) sometimes useful.