Hi,
I've got a lot of functions (compression, encryption, hashing,
encoding, etc) that work on a memory range.
I wrote my own class that has constructors for
void*, void*
void*, size_t
std::string&
and that automatically reinterpret_cast to unsigned char*.
But I'm wondering, is there a standard C++ or Boost class that already
does this?
Or is there a better way to do this?
|
|
0
|
|
|
|
Reply
|
OlafvdSpek (15)
|
5/8/2006 10:01:39 AM |
|
Olaf van der Spek wrote:
> I've got a lot of functions (compression, encryption, hashing,
> encoding, etc) that work on a memory range.
> I wrote my own class that has constructors for
> void*, void*
> void*, size_t
> std::string&
> and that automatically reinterpret_cast to unsigned char*.
>
> But I'm wondering, is there a standard C++ or Boost class that already
> does this?
> Or is there a better way to do this?
The standard C++ way is to use containers like list, vector,
and such, and not to do the reinterpret_cast thing.
Socks
|
|
0
|
|
|
|
Reply
|
puppet_sock (479)
|
5/8/2006 2:58:12 PM
|
|
On 8 May 2006 07:58:12 -0700, "Puppet_Sock" <puppet_sock@hotmail.com>
wrote:
>Olaf van der Spek wrote:
>> I've got a lot of functions (compression, encryption, hashing,
>> encoding, etc) that work on a memory range.
>> I wrote my own class that has constructors for
>> void*, void*
>> void*, size_t
>> std::string&
>> and that automatically reinterpret_cast to unsigned char*.
>>
>> But I'm wondering, is there a standard C++ or Boost class that already
>> does this?
>> Or is there a better way to do this?
>
>The standard C++ way is to use containers like list, vector,
>and such, and not to do the reinterpret_cast thing.
I know, but that doesn't work if you're doing low-level stuff and the
functions you're calling except pointers.
|
|
0
|
|
|
|
Reply
|
OlafvdSpek (15)
|
5/8/2006 3:47:41 PM
|
|
"Olaf van der Spek" <OlafvdSpek@GMail.Com> wrote in message
news:8d5u52hnnjh1dsts6rg17tboq1ut8k6cjj@4ax.com...
: I've got a lot of functions (compression, encryption, hashing,
: encoding, etc) that work on a memory range.
: I wrote my own class that has constructors for
: void*, void*
: void*, size_t
: std::string&
: and that automatically reinterpret_cast to unsigned char*.
:
: But I'm wondering, is there a standard C++ or Boost class that already
: does this?
The usual approach is to pass a pair of poiters or iterators
that define the bounds of data to be processed (begin-end).
: Or is there a better way to do this?
The standard/generic approach is to write template functions
that can process different kinds of data ranges. It might
also be desirable to separate the input and output buffers.
For example, consider std::transform:
void transform( srcBegin, srcEnd, dstBegin, operation );
Of course, many low-level utilities prefer to process
memory ranges, or memory chunks.
Another standard approach would be to use streams. But then
again, standard classes are geared towards text-based i/o.
The binary-level streambuf does not provide separate input-only
and output-only classes. Plus locale and facet handling impair
efficiency.
So, IMO, when one wants to do low-level binary processing, one
should not count too much on standard library support.
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
|
|
0
|
|
|
|
Reply
|
INVALID_use_webform (179)
|
5/8/2006 8:23:02 PM
|
|
On Mon, 8 May 2006 22:23:02 +0200, "Ivan Vecerina"
<INVALID_use_webform@ivan.vecerina.com> wrote:
>"Olaf van der Spek" <OlafvdSpek@GMail.Com> wrote in message
>news:8d5u52hnnjh1dsts6rg17tboq1ut8k6cjj@4ax.com...
>: I've got a lot of functions (compression, encryption, hashing,
>: encoding, etc) that work on a memory range.
>: I wrote my own class that has constructors for
>: void*, void*
>: void*, size_t
>: std::string&
>: and that automatically reinterpret_cast to unsigned char*.
>:
>: But I'm wondering, is there a standard C++ or Boost class that already
>: does this?
>
>The usual approach is to pass a pair of poiters or iterators
>that define the bounds of data to be processed (begin-end).
But using two arguments is a disadvantage, see also Boost.Range.
For example, you can't use automatic conversion.
>So, IMO, when one wants to do low-level binary processing, one
>should not count too much on standard library support.
That's a shame, as I think it's a frequent task.
|
|
0
|
|
|
|
Reply
|
OlafvdSpek (15)
|
5/9/2006 8:03:32 AM
|
|
Olaf van der Spek wrote:
> On Mon, 8 May 2006 22:23:02 +0200, "Ivan Vecerina"
> <INVALID_use_webform@ivan.vecerina.com> wrote:
>
>
>>"Olaf van der Spek" <OlafvdSpek@GMail.Com> wrote in message
>>news:8d5u52hnnjh1dsts6rg17tboq1ut8k6cjj@4ax.com...
>>: I've got a lot of functions (compression, encryption, hashing,
>>: encoding, etc) that work on a memory range.
>>: I wrote my own class that has constructors for
>>: void*, void*
>>: void*, size_t
>>: std::string&
>>: and that automatically reinterpret_cast to unsigned char*.
>>:
>>: But I'm wondering, is there a standard C++ or Boost class that already
>>: does this?
>>
>>The usual approach is to pass a pair of poiters or iterators
>>that define the bounds of data to be processed (begin-end).
>
>
> But using two arguments is a disadvantage, see also Boost.Range.
> For example, you can't use automatic conversion.
>
>
>>So, IMO, when one wants to do low-level binary processing, one
>>should not count too much on standard library support.
>
>
> That's a shame, as I think it's a frequent task.
What would you expect a library to do in this case? You have a block of
data to process, which requires two parameters to define it, unless it
has an end marker.
--
Ian Collins.
|
|
0
|
|
|
|
Reply
|
ian-news (9881)
|
5/9/2006 8:08:03 AM
|
|
On Tue, 09 May 2006 20:08:03 +1200, Ian Collins <ian-news@hotmail.com>
wrote:
>Olaf van der Spek wrote:
>>>So, IMO, when one wants to do low-level binary processing, one
>>>should not count too much on standard library support.
>>
>>
>> That's a shame, as I think it's a frequent task.
>
>What would you expect a library to do in this case? You have a block of
>data to process, which requires two parameters to define it, unless it
>has an end marker.
I expected it to have a class like pair<unsigned char*, unsigned
char*> with constructors that take (void*, void*), (void*, size_t),
(const string&), etc.
|
|
0
|
|
|
|
Reply
|
OlafvdSpek (15)
|
5/9/2006 8:15:27 AM
|
|
|
6 Replies
19 Views
(page loaded in 0.475 seconds)
|