Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2003
rodrigc rodrigc is offline
Registered User
 
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 27
Cool Questions about sequence<byte> in C++?

Hi,

In CORBA C++, I'm used to dealing with sequence<octet>.
This maps to a CORBA::Octet buffer (which basically is a char buffer),
which you can manipulate quite
easily with get_buffer() and replace().

In Ice, a sequence<byte> maps to a vector<Ice::Byte>.

Is there a way to do the CORBA C++ equivalent of get_buffer() and
replace()?

To try thiings out in Ice, I made an interface::

sequence<byte> FrameData;

interface FrameOps
{

void sendFrame(FrameData f);
};

My client code looks like (eliminating all the Ice boilerplate to
get an object reference to a FrameOps object:

std::ifstream f;
f.open(argv[1], std::ios_base::binary);

if( f.fail() ) {
std::cout << "Failed" << std::endl;
return -1;
}

f.seekg(0, std::ios_base::end);
long len = f.tellg();
std::cout << "Pos: " << len << std::endl;
f.seekg(0, std::ios_base::beg);

Ice::Byte *buf = new Ice::Byte[len];
f.read(buf, len);

FrameData v(&buf[0], &buf[len]);
frame_ops->sendFrame(v);


Using this technique, I have to create
a separate Ice::Byte buffer, and then
copy that into a vector<Ice::Byte>
before calling the remote method.

Is there a more optimal way for me to do this, or is this the best way?

Thanks.
__________________
--
Craig Rodrigues
Reply With Quote
  #2 (permalink)  
Old 02-24-2003
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
Re: Questions about sequence<byte> in C++?

Quote:
Originally posted by rodrigc
Hi,

Using this technique, I have to create
a separate Ice::Byte buffer, and then
copy that into a vector<Ice::Byte>
before calling the remote method.

Is there a more optimal way for me to do this, or is this the best way?

Thanks.
The latest version of the C++ standard guarantees that, for an STL vector, the elements are kept in contiguous memory. (Even before that standards update, all extant implementations maintained that guarantee.) So, you can just use the address of the first element of a vector as a buffer pointer and go for your life.

Cheers,

Michi.
Reply With Quote
  #3 (permalink)  
Old 02-24-2003
rodrigc rodrigc is offline
Registered User
 
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 27
Cool

Hi,

OK, I simplified myt code and it works great!
I changed it to:

================================================== ========
std::ifstream f;
f.open(argv[1], std::ios_base::binary);

if( f.fail() ) {
std::cout << "Failed" << std::endl;
return -1;
}

f.seekg(0, std::ios_base::end);
long len = f.tellg();

f.seekg(0, std::ios_base::beg);

FrameData v(len);
f.read(&v[0], len);
frame_manip->sendFrame(v);

frame_ops->sendFrame(v);

================================================== ========

Thanks!
__________________
--
Craig Rodrigues
Reply With Quote
  #4 (permalink)  
Old 02-24-2003
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
Quote:
Originally posted by rodrigc
Code:
FrameData v(len);
f.read(&v[0], len);
frame_manip->sendFrame(v);

frame_ops->sendFrame(v);
Yep, that's it. Nice, isn't it? A sequence abstraction that guarantees contiguous memory is definitely nice for things such as binary data. No more mucking around with get_buffer() and set_buffer() and such

Cheers,

Michi.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Patch #6 for Ice 3.1.0: byte sequences in dictionaries dwayne Patches 1 07-31-2006 10:35 AM
UnmarshalOutOfBoundsException when sending byte sequences csammis Help Center 3 08-03-2005 04:37 PM
Questions about sanity-check of sequence sizes during sequence unmarshaling rc_hz Help Center 4 06-22-2005 10:33 PM
Ice::Byte question.. yserge Help Center 1 08-19-2004 06:54 PM
Chars to Ice::Byte catalin Help Center 6 12-14-2003 10:03 AM


All times are GMT -4. The time now is 11:16 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.