473,797 Members | 3,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass memory range to functions?

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_cas t 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?
May 8 '06 #1
6 2016
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_cas t 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_cas t thing.
Socks

May 8 '06 #2
On 8 May 2006 07:58:12 -0700, "Puppet_Soc k" <pu*********@ho tmail.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_cas t 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_cas t thing.


I know, but that doesn't work if you're doing low-level stuff and the
functions you're calling except pointers.
May 8 '06 #3
"Olaf van der Spek" <Ol********@GMa il.Com> wrote in message
news:8d******** *************** *********@4ax.c om...
: 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_cas t 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
May 8 '06 #4
On Mon, 8 May 2006 22:23:02 +0200, "Ivan Vecerina"
<IN************ *****@ivan.vece rina.com> wrote:
"Olaf van der Spek" <Ol********@GMa il.Com> wrote in message
news:8d******* *************** **********@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_cas t 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.
May 10 '06 #5
Olaf van der Spek wrote:
On Mon, 8 May 2006 22:23:02 +0200, "Ivan Vecerina"
<IN************ *****@ivan.vece rina.com> wrote:

"Olaf van der Spek" <Ol********@GMa il.Com> wrote in message
news:8d****** *************** ***********@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_cas t 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.
May 10 '06 #6
On Tue, 09 May 2006 20:08:03 +1200, Ian Collins <ia******@hotma il.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.
May 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1937
by: DamonChong | last post by:
Hi, I am still struggling to master C++ and is trying to understand how to achieve passing arguments using pointers. I got some questions that I like to post to the experts here, hope you can help to clarify my doubts. I'm using g++ version 3.3.4. I created 3 classes as below for testing some concepts. The questions are written as comments in Bclass.h file. Thank you for your time and tips! ------------runtime errors------------
4
7288
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel file being created, it will be sent out via email to the list of recipients. I run the script on my notebook (also developed on th same machine) it works fine. However, when I copy all the programs into the server which running on Windows 2000...
7
4694
by: toton | last post by:
Hi, I have a STL vector of of characters and the character class has a Boost array of points. The things are vector<Characterchars; and class Character{ private: array<Point,Npoints; }; Now are the memory layout is contiguous? i.e all the character resides side by side just like array, and all Points side by side insede the
14
20414
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
6
2714
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as pass by reference in C since you are just passing an address (or a pointer value address I guess?). So I was wondering is this correct?
11
3367
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible ways of passing an array. In the following code, fun1(int a1) - same as fun1(int* a1) - where both are of the type passed by reference. Inside this function, another pointer a1 is created whose address &a1 is different from that of the passed...
62
2369
by: Generic Usenet Account | last post by:
A lot of research has been done to prove that the contention that C code is more efficient and more compact than equivalent C++ code is a myth. My posting pertains to a slightly different aspect of this debate. Here are my two questions: 1) Does anyone have any information on comparison of C and C++ software written for the ARM processor? 2) Are there any compiler and CPU dependencies that have to be factored in while debating this...
12
3020
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
1
6302
by: Nagu | last post by:
I didn't have the problem with dumping as a string. When I tried to save this object to a file, memory error pops up. I am sorry for the mention of size for a dictionary. What I meant by 65000X50 is that it has 65000 keys and each key has a list of 50 tuples. I was able to save a dictionary object with 65000 keys and a list of 15-tuple values to a file. But I could not do the same when I have a list of 25-tuple values for 65000 keys.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.