Boost logo

Boost Users :

Subject: Re: [Boost-users] Compress to buffer
From: Kenneth Adam Miller (kennethadammiller_at_[hidden])
Date: 2014-01-15 23:08:42


On Tue, Jan 14, 2014 at 7:46 PM, Kenneth Adam Miller <
kennethadammiller_at_[hidden]> wrote:

>
>
> On Tue, Jan 14, 2014 at 1:58 PM, Kenneth Adam Miller <
> kennethadammiller_at_[hidden]> wrote:
>
>> Thank you.
>>
>>
>> On Tue, Jan 14, 2014 at 1:55 PM, Krzysztof Czainski <1czajnik_at_[hidden]>wrote:
>>
>>> 2014/1/14 Kenneth Adam Miller <kennethadammiller_at_[hidden]>
>>>
>>>> Ah ok. I apologize for posting too fast. I will be sure to go further
>>>> in exhausting all resources before I post in the future. However, I did
>>>> find some of the descriptions of the iostreams parts and how they compose
>>>> (especially examples, that's what I was really looking for) vague, IMHO.
>>>>
>>>> No, I haven't measured performance.
>>>>
>>> [...]
>>>
>>>> Those unnecessary allocation copies would, in the worst case, result
>>>> in a 2-3x slowdown of the entire program
>>>>
>>>
>>> How do you know?
>>>
>>>
>>>> due to the fact that it's literally pausing to repeat something that's
>>>> unnecessary.
>>>>
>>>> But actually, if this appends my 30k string, I didn't know it. The
>>>> back_insert_device<string> object wasn't something that I understood very
>>>> well from the description at
>>>> http://www.boost.org/doc/libs/1_45_0/libs/iostreams/doc/classes/back_inserter.html
>>>>
>>>> From what I had thought though, if my string was empty with 0's,
>>>>
>>>
>>> Right here's your mistake. string(30000,0) creates a non empty string.
>>> It's a string of 30k nulls.
>>>
>>>
>>>> and I appended to it, then I would end up with precisely my compressed
>>>> data. The idea of acquireStringFromPool is that it returns a large string
>>>> that is always cleared out for the filtering_ostream to fill up as though
>>>> it were a device. Is that incorrect? How can I get that functionality?
>>>>
>>>
>>> Like I said, you want std::vector::reserve().
>>>
>>
> Ok, so supposing I just use a vector; do I use vector<byte>? Is it more
> efficient to use vector< word_size_of_computer > since any write to it
> would obviously be faster or will the compiler catch this? Also, when I
> grab all of the bytes from vector, does it automatically detect when the
> end is? Like, one of the purposes of having 0's all through the string was
> so that it was always terminated. In the case of vector, if I push_back 3
> times, and then I output, will I get 3 bytes?
>

Also, supposing I go with something like vector<int64_t> or something, how
do I create a device to make the filtering stream complete? I had:
    fos->push(boost::iostreams::back_insert_device<string>(*x));
now I need to do:
    fos->push(boost::iostreams::back_insert_device<vector<int64_t>>(*x));
but it complains with "error: no matching function for call to" construct
it, and then says that it wants one of a ton of different valid things, but
it template expands all of them so it's a bunch of text...

>
>
>>
>>> Perhaps, however, that reserve approach would be good. I apologize the
>>>> email was so long lol.
>>>>
>>>
>>> Btw, you're still top-posting. The idea is to leave the (minimal)
>>> context above your reply message ;-)
>>>
>>> By top posting you meant just the position of my text. I thought you
>> meant it to be me posting when I could have more fully investigated the
>> issue. I will follow this convention.
>>
>>
>>> Regards,
>>> Kris
>>>
>>>
>>> _______________________________________________
>>> Boost-users mailing list
>>> Boost-users_at_[hidden]
>>> http://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