Boost logo

Boost Users :

Subject: Re: [Boost-users] (Newbie) Embedded programming, memory pools, and allocate_shared()
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2017-12-06 05:33:20


On Tue, Dec 5, 2017 at 4:18 PM, Steven Boswell II via Boost-users
<boost-users_at_[hidden]> wrote:
> I apologize for bothering the mailing-list with this newbie question, but
> after searching the Net for several days, I still can't find the answers I'm
> looking for.

I don't know about "embedded systems" in general. That's a pretty wide
swath. Are we talking about Motorola? ARM?

I've managed to add Boost support to an ARM based embedded ArchLinux.
Works pretty well. The trick is finding the right host/target
combination for cross compilation. All very doable, and there are
build environments available for just about any combination.

> I am considering using Boost for a project I'm doing on an embedded system.
> I can't seem to find a lot of discussion on the particulars of Boost in
> embedded systems, just a few here and there.
> The biggest relevant limitation in embedded programming is on dynamic memory
> allocation -- the usual pattern is to allocate all necessary memory in
> "startup" phases, e.g. launching the program, loading the next playing-field
> in a game application, etc.
>
> I believe I can do what I want with allocate_shared() and fixed-size memory
> pools.
> The first big issue I have is trying to figure out the size of the objects
> that'll be allocated from the pool.
> I don't want to just allocate a raw block of memory; I want to allocate a
> block with space for a certain number of objects of a homogeneous type.
> But an object_pool for a type T doesn't accurately reflect what
> allocate_shared() is going to try to create.
> From much digging around, it looks like it's actually creating a subclass of
> boost::detail::sp_counted_base, e.g. boost::detail::sp_counted_impl_pd<P,D>,
> boost::detail::sp_counted_impl_pda<P,D,A>, etc.
> It seems like I'm not supposed to refer to that class directly, but I don't
> know how else to get the size of individual objects for my pool-allocator.
> Also, navigating all the template-parameters needed by these classes is
> proving to be mind-twisting. Probably just because I'm seeing it for the
> first time.
>
> Another example of where I need to track down the implementation class is
> with async-operation handlers in Boost::ASIO, e.g. completion handlers for
> socket's async_read_some(), generic handlers passed to io_service::post(),
> and so on. In the case of socket::async_read_some(), there's an example in
> boost/doc/html/boost_asio/example/cpp03/allocation/server.cpp which shows
> how to allocate completion-handlers from a pool, but not how to get the size
> of the necessary completion-handler class. It appears the class is
> boost::asio::detail::reactive_socket_recv_op<>. Again, this doesn't seem to
> be a public class, nor can I find a nice public typedef for it.
>
> Can anyone advise me on how to use Boost in this way?
> All of the Boost memory-pools I've seen so far either just allocate chunks
> of raw memory, or they allocate non-shared variants of objects.
> A memory-pool with a given number of spaces for the final object type seems
> like a defensible, traditional solution, but it doesn't seem that Boost
> makes that easy.
> Am I way off base here?
>
> Thanks for any help.
>
> -Steven
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net