|
Boost Users : |
Subject: Re: [Boost-users] Using boost with 'c' level interfaces ?
From: Slava (Viatcheslav.Sysoltsev_at_[hidden])
Date: 2013-06-07 02:52:30
On Thu, 06 Jun 2013 19:07:20 +0200, avib369 . <avibahra_at_[hidden]> wrote:
> I can not find any solution where a 'c' api
> can update/modify a std::vector
>
> Passing a std::vector<int>/std::vector<double> to a
> 'c' or fortran api function, that _reads_, works like a charm.
>
> However we are out of luck, if we need the 'c' api, to
> populate the array. When passing a std::vector will
> 'kind of' work. But you can never use any of the following
>
> // 1/ size()
> // 2/ empty()
> // 3/ begin()/ end()/ rbegin()/rend()
> // 4/ push_back()
> // 5/ pop_back()
>
> You have to separately carry the size of the vector, in
> order to use it. You then just end up using it like a 'c' array.
> I thought there may have been way of updating the vectors
> begin/finish after the api call. But there does not appear to
> any way to do this.
>
> One solution would be to use 'c' array when calling the
> interface, and then copy to a std::vector.
> However this would degrade performance, when dealing large data sets.
>
> Is there any boost libraries/containers that are applicable or that
> can handle this issue ? It must have similar properties to a vector,
> like contiguous memory ?
>
> I have included a sample program below, to demonstrate.
>
> Before resorting back to 'c' array I was wondering
> if any one else has come across this problem ?
>
> Ta,
> Avi
Hi Avi,
I was once fascinated how gtk reimplements the objects in C. Maybe you can
use gtk array (https://developer.gnome.org/glib/stable/glib-Arrays.html)?
-- Slava
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