Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

some questions

33 views
Skip to first unread message

Bonita Montero

unread,
Nov 14, 2019, 11:24:49 AM11/14/19
to
I use a vector to store one or two thread-objects which I emplace_back.
I later join the threads. I'd rather like to use a array<thread, 2>
but an array<> hasn't a dynamic size ore more precise, a size and a
capacity. But I need a size since I can't determine if a thread-object
has an attached thread (doing threadObj.getId() != thread::id() doesn't
work).
So there are two alternatives:
1. Is there a prebuilt class somewhere in boost or wherever that has
a static internal capacity but a dynamic size? Something like a
more advanced array<T, N>?
2. Is there another way to detect if a thread-object has an attached
"physical" thread?

Bonita Montero

unread,
Nov 14, 2019, 12:45:49 PM11/14/19
to
Sorry, "threadObj.get_id() != thread::id()" worked. I did a "=="
instead of a "!=". But the question of the dynamic / static array
is still interesting for me.

Martijn van Buul

unread,
Nov 25, 2019, 3:04:19 AM11/25/19
to
* Bonita Montero:
> 1. Is there a prebuilt class somewhere in boost or wherever that has
> a static internal capacity but a dynamic size? Something like a
> more advanced array<T, N>?

boost::container::static_vector<T, size>

but one could also consider using a plain old std::vector with a custom
std::allocator.

--
Martijn van Buul - pi...@dohd.org

Bonita Montero

unread,
Nov 25, 2019, 3:23:26 AM11/25/19
to
> but one could also consider using a plain old std::vector with a custom
> std::allocator.

Doesn't work since it isn't guaranteed that a container doesn't do
a typename std::allocator_traits<Old>::template rebind_alloc<New>
to do multiple allocations of different type on one container. I
wrote a custom allocator some time ago which mapped to mmap() or
VirtualAlloc() but I found that the std::vector<T>-implementation
of MSVC does a rebind_alloc and has an additional allocation.
So alllocators simply must support full heap-semantics to be
compatible to containers.
0 new messages