> -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of James Newtons Massmind > Sent: Friday, February 24, 2006 7:28 PM > To: 'Microcontroller discussion list - Public.' > Subject: [EE] selecting the right C++ STD library memory buffer > > The programmer I hired to help with this is sick and make take some time > to > reply so I'll write the list with this question in hopes of finding an > answer faster. > > I'm writing Win32 code in C/C++ (MS Visual C++ 2005 Express Edition) and > part of this code manipulates data that is handed to it in a memory > buffer. > I may have to insert things and thereby increase the size of the data > beyond > the size of the source buffer. So I need to allocate a buffer of my own, > copy from the source and insert my bits, the return the result in place of > the source. No problems so far. > > The issue is what class to use for my buffer. Here are the requirements: > 1. It should be as efficient and fast as possible. E.g. I don't need file > IO > so there is no reason to use a iostream class. > > 2. The data is binary. By that I mean the byte values will range from 0 to > 255. Some of the data I will put into the buffer is binary, but other data > will be text and some data will be binary values (int, short, etc...) that > I > will need to convert to decimal characters and append. E.g. if it was an > std::basic_stringstream I would use: > > std::basic_stringstream buffer; > int I = 123; > buffer << "I is:" << I; > > So the issue is this combination of needs: copying in parts of a binary > char > array, text, or decimal values of variables. > > What class does all that? And more importantly, where is there any > documentation that would help a poor newbie like me figure out what they > do > and don't? > > I've been advised to use vector but that doesn't support the << and the > copy > as far as I can see. Derive a class from any of the C++ STL and you can add any features you want. One of the annoying things about C++ is that they broke some of the simplicity of C. What do you want << to mean? Do you mean send the whole structure to an iostream? Binary shift some or all of the elements? All C++ STL container classes can be copied. What do you mean by that? > I've also been advised not to use streams as they don't play well with > binary? Depends what you mean by play nice. I use binary elements into streams all the time. > > Any advice appreciated. STL container type choice depends upon what the most common operation is. I can help you with this on or off list but I'd need a better specification of exactly what kind of data you want to handle. Is it this sort of stuff? This was a five minute type in using Visual Studio.Net (even though I hate .net) // CharList.cpp : Defines the entry point for the console application. // #include #include typedef std::list < unsigned char > charList; unsigned char a [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; unsigned char b []; int main(int , char* ) { charList l; for (unsigned idx = 0; idx <= sizeof(a); ++idx) { // an insert before for no particular reason if ( a [idx] == 2) { l.push_back(2); } l.push_back ( a [idx] ); // an insert after again for no aprticular reason if (a [idx] == 7) { l.push_back( 11 ); } } for ( charList::iterator itr = l.begin(); itr != l.end(); ++itr ) { if ( *itr == 6 ) { l.insert ( itr, 250 ); } } for ( charList::const_iterator itr = l.begin(); itr != l.end(); ++ itr) { std::cout << (unsigned)*itr << std::endl; } return 0; } ------------------------------------- Notice of Confidentiality ---------------------------------------------------------- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify postmaster@vgt.net. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist