Live data from Hacker News

The PImpl idiom and the C++26 std:indirect type

mariusbancila.ro

121–122 of 122 posts

Re: The PImpl idiom and the C++26 std:indirect type

#121

Earlier quoted context omitted.

> I gave you great information "Great" is quite debatable. In any case, nothing I hadn't already known. > You aren't going to notice all your concurrency bugs without threads. True, but my problem was neither proper locking / thread safety, nor reference counting. You still felt the need to explain to me because you don't realize the problem isn't that I don't understand what you say. The problem is that you don't un…

In any case, nothing I hadn't already known. I at least showed you cppreference so you can look up the data structures and their guarantees. True, but my problem was neither proper locking / thread safety, nor reference counting. But you did blame the STL for concurrency bugs so there must have been something. prefer to invite tons of unnecessary boilerplate I'm not sure a heavily tested and fast lock free queue libr…

> I at least showed you cppreference so you can look up the data structures and their guarantees.

Why do you show this to me??? Don't you think I know it?

> But you did blame the STL for concurrency bugs so there must have been something.

I explained the problem at your request: I pointed out that this was a bug I introduced myself, but yes, I blamed it on STL (and its complexity). Again, it was abstractly a "concurrency" problem, and it did manifest when using multiple threads, but the problem was not due to missing mutex nor reference counting. Instead it was because of a kind of iterator invalidation that I had not expected at the time of banging out some shitty iterator code. The uniform iterator abstraction made it arguably way easier to miss.

> You used C++'s dequeue, wouldn't that be boilerplate by this bizarre definition?

yes absolutely, std::deque is a super bad offender, in many ways. I advise against using it. More than against using STL in general, although I don't recommend that either.

> I think you might have misunderstood that the reference counting is for anything returned from a data structure so that it can see that something is being used and not modify it. The reference counts of the returned object are actually pointers to the internal reference counts in the data structure, like checking out a library book.

No I have not misunderstood anything. Again you're coming back to your arrogant pattern. There are many ways to implement reference counting. When doing it manually instead of with e.g. std::shared_ptr, it's quite common to embed the count inside the object, not make it a separate allocation.

> This is not how I would do a queue though and not how the queues I linked work. They copy data in and out and are best used for small data. Large amounts of data can be handled in a different way by a different structure.

There are many types of queues. There are queues that buffer two elements, there are queues that buffer millions of elements. There are queues that get persisted (like a database). There are queues that are ephemeral. There are queues that have multiple produces and/or consumers, there are queues with only a single producer/consumer. There are queues that get locked. There are queues that get accessed with atomics only. There are queues that store elements directly. There are queues that store elements buffered in chunks or packets... "Queue" typically implies FIFO but not always.

> The C style allocation of structs to pointers then allocation of the underlying data is two allocations and double indirection.

But I rarely don't do that. And that's not implied by "C style" at all. And importantly, structure (pointer indirection) doesn't imply allocation strategy.

> Well.. we all get bit by standard library assumptions from time to time and need to read the docs, but it just isn't a concurrency problem with the STL.

I have explained the issue at length. So please stop repeating made-up contradictions.

> Claims without evidence unfortunately. The fast concurrent queues I linked are great and using destructors to keep track of reference counts is great. Both are minimal.

Claims without evidence unfortunately... Except, it's quite evident that there is a lot of code in them and it's hard to find out how anything works because of that. How would I even evaluate if the queue is doing what I need? That queue functionality implemented here should probably be a tenth of that code (!).

> I would say inserting resource management manually into every function is boilerplate.

Good, because I don't do that at all. And I criticize that RAII is a system that sneaks in resource management _implicitly_ everywhere, which is not visible in the source code. That's why I prefer C-style: making it explicit, allowing me to find the optimal structure that avoids unnecessary fluff in the first place.

Re: The PImpl idiom and the C++26 std:indirect type

#122

Earlier quoted context omitted.

In any case, nothing I hadn't already known. I at least showed you cppreference so you can look up the data structures and their guarantees. True, but my problem was neither proper locking / thread safety, nor reference counting. But you did blame the STL for concurrency bugs so there must have been something. prefer to invite tons of unnecessary boilerplate I'm not sure a heavily tested and fast lock free queue libr…

> I at least showed you cppreference so you can look up the data structures and their guarantees. Why do you show this to me??? Don't you think I know it? > But you did blame the STL for concurrency bugs so there must have been something. I explained the problem at your request: I pointed out that this was a bug I introduced myself, but yes, I blamed it on STL (and its complexity). Again, it was abstractly a "concurr…

Why do you show this to me??? Don't you think I know it?

I don't know what you are upset by this, cppreference is great and it explains the problem you had.

I blamed it on STL (and its complexity).

If you make a simple dequeue with a vector any resize is going to invalidate pointers. It isn't the STL's fault, it's meant to queue simple data for ordering so that you can copy it in and out, not hold on to a pointer to something internal. It isn't meant for actual storage just basic structure.

std::deque is a super bad offender, in many ways. I advise against using it.

You brought it up as something you were using.

No I have not misunderstood anything. Again you're coming back to your arrogant pattern.

It's not arrogant to point out how things work. In this case the pointer to a reference count is pointing to internal data in the data structure so that other threads can see it. This is not the same as shared_ptr which is tracking a reference count of itself.

But I rarely don't do that. And that's not implied by "C style" at all.

So you frequently do that? It's your C style, that's what you showed me and it takes two heap allocations so that a pointer can be returned. If you create a pointer to a struct in a function it can't point to the stack inside the function.

So please stop repeating made-up contradictions.

You did say you got burned by an assumption of pointer invalidation and that was your explanation for how the STL gave you problems with concurrency.

Claims without evidence unfortunately...

There are benchmarks and lots of people use these queues. I've used them and you can use them yourself. It isn't like saying something is bad then not being able to explain it. You and anyone else can and do use these. It is an opinion, but it is backed up by a lot including a great interface.

Good, because I don't do that at all.

Then you probably have memory leaks because you need to call the free functions that you make when you create a data structure.

And I criticize that RAII is a system that sneaks in resource management _implicitly_ everywhere

No, you said that it created implicit program flow, now you're walking that back I guess.

Also it isn't everywhere, it's only where it needs to be, so I don't know why you wouldn't want it there.

Post reply on HN