Searching \ for '[EE] selecting the right C++ STD library memory bu' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/mems.htm?key=memory
Search entire site for: 'selecting the right C++ STD library memory bu'.

Exact match. Not showing close matches.
PICList Thread
'[EE] selecting the right C++ STD library memory bu'
2006\02\24@192828 by James Newtons Massmind

face picon face
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<wchar_t> 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.

I've also been advised not to use streams as they don't play well with
binary?

Any advice appreciated.

---
James Newton: PICList webmaster/Admin
spam_OUTjamesnewtonTakeThisOuTspampiclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com


2006\02\24@224458 by Chris Levin

flavicon
face
James Newtons Massmind wrote:

{Quote hidden}

Take a look at the ArrayList class. It can do the things you need. It
can grow dynamcially, it takes any object types  and it can be efficient
in speed and memory. Check out the documentation to see how it's used
and see some samples. That will let you know for sure if it meets your
needs.

-Chris

2006\02\27@105157 by William Killian

flavicon
face


> -----Original Message-----
> From: piclist-bouncesspamKILLspammit.edu [.....piclist-bouncesKILLspamspam.....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<wchar_t> 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 <list>
#include <iostream>

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
EraseMEpostmasterspam_OUTspamTakeThisOuTvgt.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.

2006\02\27@142905 by James Newton, Host

face picon face
<snip>

> >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.

<snip>

> Take a look at the ArrayList class. It can do the things you
> need. It can grow dynamcially, it takes any object types  and
> it can be efficient in speed and memory. Check out the
> documentation to see how it's used and see some samples. That
> will let you know for sure if it meets your needs.

Thanks for the advice, but ArrayList seems to keep a series of separate
arrays each as an entry in a list. I need something that can be returned as
a solid, contiguous block of memory. I have to return a pointer to a large
array of characters and I'm trying to find easy ways to append thing to the
end of that array.

I guess I was under the impression that C++ actually made things /easier/ to
do than what was available in just C. It appears that C++ gives you many
more interesting things that you can do, but they are all more complex and
so far as I can see actually /more/ difficult.

Just for the sake of discussion and to see if there are any other points of
view out there...

In VB or something like that I could just do

i = 0
S = s & "hello" & Chr(i) & CStr(i) & Chr(27)
REM the CStr probably isn't required, but makes it more clear.

And I would have a buffer with the following hex values in it:
68 65 6C 6C 6F 00 30 1b
"h "e "l "l "o  i (i)27

In Perl, I would use the pack function:

$i = 0;
$s = pack("AXCAXC", "hello", $i, $i, "\x1b");
# the X after the A "backs up" the result to overwrite the space
# which is added by default after an ASCII string.

The equivalent code in C is something like

char I = 0;
char s[999];
char *si = s;

si = strcpy( *si, "hello");
*si++ = i;
si += sprintf( *si, "%c", i);
*si++ = 0x1b;

And I've probably made some stupid mistake there as I'm a little rusty on C
code. The problem with that is that the buffer may grow very large and so
the dynamic increase in size of the vector class in C++ is really nice. But
as far as I can see, you can only use .push_back(char) to add one character
at a time to the buffer. To add strings and decimal values, I apparently
have to write some abortion like this?

typedef std::vector<char> buffer;
typedef std::istreambuf_iterator<buffer::value_type> bufiter;
   
buffer s;
char i = 0;
std::basic_stringstream<char> temp1;
std::basic_stringstream<char> temp2;

temp1 << "hello";
std::copy(bufiter(temp1),bufiter(),std::back_inserter(s));
s.push_back(i);
temp2 << i;    
std::copy(bufiter(temp2),bufiter(),std::back_inserter(s));
s.push_back(0x1b);

But at least I can keep doing stuff like that as long as I want... And with
a good C++ compiler, that will run pretty fast. Of course, something has to
be done about the temp variables as I can't for the life of me seem to find
a method that clears out a basic_stringstream to allow it to be reused...

But this can NOT be right, right? The C++ standard library must have made it
easier to append text, binary values, and decimal conversions of values to a
contiguous array of characters? It just can NOT be that Visual Basic is
better for this...

P.S. If someone will check my C (and other) code and post the corrections,
I'll put this up on the web site as an example of how to do the same basic
thing in VB, Perl, C and C++

---
James Newton: PICList webmaster/Admin
jamesnewtonspamspam_OUTpiclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com


2006\02\27@143814 by James Newton, Host

face picon face
> > 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.

Ahh... Well... Probably beyond me at this point.

> 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?

It is confusing, yes...

> All C++ STL container classes can be copied.  What do you
> mean by that?

How do I copy something into a std:vector other than looping through it one
character at a time and using push_back? Or better yet, see the other post I
just sent on this subject.

> > 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.

www.sunsite.ualberta.ca/Documentation/Gnu/libstdc++-2.90.8/html/27_io
/howto.html but again, I don't really need io, so it seems wastefull to use
a class that supports it.

> > 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.

Best to see my other post as it gives an example that (I hope) makes it more
clear.

Thanks for responding...

---
James Newton: PICList webmaster/Admin
@spam@jamesnewtonKILLspamspampiclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com


2006\02\27@170415 by William Killian

flavicon
face


> -----Original Message-----
> From: KILLspampiclist-bouncesKILLspamspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspammit.edu] On
Behalf
{Quote hidden}

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
{Quote hidden}

separate
> arrays each as an entry in a list. I need something that can be
returned
> as
> a solid, contiguous block of memory. I have to return a pointer to a
large
> array of characters and I'm trying to find easy ways to append thing
to
> the
> end of that array.
>
> I guess I was under the impression that C++ actually made things
/easier/
> to
> do than what was available in just C. It appears that C++ gives you
many
> more interesting things that you can do, but they are all more complex
and
> so far as I can see actually /more/ difficult.
>
> Just for the sake of discussion and to see if there are any other
points
{Quote hidden}

This will work in C++ nearly all C programs are C++ programs as well.



>
> And I've probably made some stupid mistake there as I'm a little rusty
on
> C
> code. The problem with that is that the buffer may grow very large and
so
> the dynamic increase in size of the vector class in C++ is really
nice.
> But
> as far as I can see, you can only use .push_back(char) to add one
> character
> at a time to the buffer. To add strings and decimal values, I
apparently
{Quote hidden}

Istreams suck.  Use the C I/O most of the time.  It's all still there.
Don't use the "basic_XX" stuff - use the more specialized ones that
match your needs.  You want 8 bit ascii use stringstream NOT
basic_stringstream.  You want wchar_t instead of char use wstringstream.

To match your C above - it makes more sense than your C++:

I'll assume cases mismatches were unintentional and you email like mine
'corrects' things it shouldn't...  

And that I is a char intended to first be added as NUL I think you
duplicated code in the C with '*si++ = i and the ssprintf version

Did you mean to put a 0x00 followed by 0x30?  Or 0 as binary and 0 as
ACII?  Lets assume you did.  You should have used a %d not %c for that

stringstream (#include <sstream>) might be what you want.



// replaces char s[] AND char * si

std::string stream ss;
// char I = 0 from your code?
Const char esc = 0x1B;
char i = 0;

// A char goes through as 'binary' while an int is converted to ASCII

ss << "hello";        // Add hello as text
ss << i;                // Add I as a NULL single byte 0
ss << (int)i;        // Add I as an ASCII string or 0x30
ss << esc;                // Add escape caharacter

Or more briefly

ss << "hello" << i << (int)i << esc;

You can then access ss as a C string as ss.str() for something like

char output [256];
memcpy(output,ss.str());

If you want to put a ascii version of an int - what you usually used
sprintf() type stuff for in C you can do

std::stringstream ss;
int ii;

ss << i and it is like you sent i to std::cout in that it gets turned
into ASCII.



>
> But at least I can keep doing stuff like that as long as I want... And
> with
> a good C++ compiler, that will run pretty fast. Of course, something
has
> to
> be done about the temp variables as I can't for the life of me seem to
> find
> a method that clears out a basic_stringstream to allow it to be
reused...


Easiest way is destruct and construct.

       for (;;)
       {
               std::stringstream ss;        // all constructed clean and
empty new

               // do new stuff to go to ss
               ss << goobledyGook();

               // now do something with the completed buffer

               doneWith(ss.str());

       } // when flow gets here the ss is destructed and goes away
}

This all make more sense?

>
> But this can NOT be right, right? The C++ standard library must have
made
> it
> easier to append text, binary values, and decimal conversions of
values to
> a
> contiguous array of characters? It just can NOT be that Visual Basic
is
> better for this...
>
> P.S. If someone will check my C (and other) code and post the
corrections,
> I'll put this up on the web site as an example of how to do the same
basic
> thing in VB, Perl, C and C++

I can fix the C and C++ when I really know what you meant.


-------------------------------------  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
spamBeGonepostmasterspamBeGonespamvgt.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.

2006\02\27@182432 by James Newton, Host

face picon face

> To match your C above - it makes more sense than your C++:

No doubt. <grin>

{Quote hidden}

Ah... Right, yes, 0x00 then 0x30 was intended so I should have used %d. And
%c would have made 0x00 then 0x00, yes, I see that is true and not what I
intended. Correct code would be:

char I = 0;
char s[999];
char *si = s;

si = strcpy( *si, "hello");
*si++ = i;
si += sprintf( *si, "%d", i);
*si++ = 0x1b;

And the result would be
68 65 6C 6C 6F 00 30 1b
"h "e "l "l "o  i (i)27

> stringstream (#include <sstream>) might be what you want.
>
>
>
> // replaces char s[] AND char * si
>
> std::string stream ss;

I'm assuming the space between string and stream is your spell checker and
it should have been "stringstream".

> // char I = 0 from your code?
> Const char esc = 0x1B;
> char i = 0;
>
> // A char goes through as 'binary' while an int is converted to ASCII
>
> ss << "hello";        // Add hello as text
> ss << i;                // Add I as a NULL single byte 0

Oh? That works? Cool! Why does that work? If "i" had been 123 it would have
appended 0x7B?

> ss << (int)i;        // Add I as an ASCII string or 0x30

And if "i" had been 123 then it would have appended 0x30,0x31,0x32?

{Quote hidden}

See, that won't work. I will have to find the length of ss, then allocate a
char array on the heap, memcpy it and then return the char array, I guess.

> If you want to put a ascii version of an int - what you usually used
> sprintf() type stuff for in C you can do
>
> std::stringstream ss;
> int ii;
>
> ss << i and it is like you sent i to std::cout in that it
> gets turned into ASCII.

But this is only because the type is int rather than char? That is confusing
as all get out. So the << appends the binary value if the types match and
the decimal value if they don't? That is NOWHERE in my documentation. Time
to start a web page...

<snip>

{Quote hidden}

I guess so. Isn't the point of an object oriented language to enable the
objects to know what to do with themselves? Why isn't it ss.doneWith? But
that isn't a question for you, rather a question for whoever writes the C++
language.

It's a strange world. But then I say that about Perl as well. And I'm sure
others feel the same about C or asm.

Thanks again.

---
James Newton: PICList webmaster/Admin
TakeThisOuTjamesnewtonEraseMEspamspam_OUTpiclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com



2006\02\27@210731 by Gerhard Fiedler

picon face
James Newton, Host wrote:

> In VB or something like that I could just do
>
> i = 0
> S = s & "hello" & Chr(i) & CStr(i) & Chr(27)
> REM the CStr probably isn't required, but makes it more clear.
>
> And I would have a buffer with the following hex values in it:
>  68 65 6C 6C 6F 00 30 1b
>  "h "e "l "l "o  i (i)27
>
> In Perl, I would use the pack function: [...]

Sounds like you wanted the string and stringstream classes...

Gerhard

2006\02\27@212130 by James Newton, Host

face picon face
Gerhard Fiedler Sent: 2006 Feb 27, Mon 18:07
>
> James Newton, Host wrote:
>
> > In VB or something like that I could just do
> >
> > i = 0
> > S = s & "hello" & Chr(i) & CStr(i) & Chr(27) REM the CStr probably
> > isn't required, but makes it more clear.
> >
> > And I would have a buffer with the following hex values in it:
> >  68 65 6C 6C 6F 00 30 1b
> >  "h "e "l "l "o  i (i)27
> >
> > In Perl, I would use the pack function: [...]
>
> Sounds like you wanted the string and stringstream classes...

As I understand it, string and stringstream do not actually maintain a
contigous area in memory where their content is accessable. E.g. you can't
point to one and read out bytes that contain what the string in basic or the
result of the pack function returns.

You then have to convert them to such an array of characters by calling
their .str() function to make an actual string from the result.

But, yes, it sounds like that is as close as it gets.

---
James Newton: PICList webmaster/Admin
RemoveMEjamesnewtonspamTakeThisOuTpiclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com


2006\02\27@222124 by Gerhard Fiedler

picon face
James Newton, Host wrote:

> As I understand it, string and stringstream do not actually maintain a
> contigous area in memory where their content is accessable. E.g. you
> can't point to one and read out bytes that contain what the string in
> basic or the result of the pack function returns.

If you return a string object (or a pointer to one), you can access
individual elements. Like with .operator[], or with .data(). I never had to
look into that in detail, but it seems to me, from the description of
data(), that the string data is contiguous.

> You then have to convert them to such an array of characters by calling
> their .str() function to make an actual string from the result.

Isn't that pretty much the same as the other languages you mentioned? (I'd
look into .data() for this.)

Gerhard

2006\02\28@103740 by William Killian

flavicon
face


> -----Original Message-----
> From: piclist-bouncesEraseMEspam.....mit.edu [EraseMEpiclist-bouncesspammit.edu] On
Behalf
> Of James Newton, Host
> Sent: Monday, February 27, 2006 6:24 PM
> To: 'Microcontroller discussion list - Public.'
> Subject: RE: [EE] selecting the right C++ STD library memory buffer
>
[...]
> > Did you mean to put a 0x00 followed by 0x30?  Or 0 as binary
> > and 0 as ACII?  Lets assume you did.  You should have used a
> > %d not %c for that
>
> Ah... Right, yes, 0x00 then 0x30 was intended so I should have used
%d.

Or %u if unsigned.

> And
> %c would have made 0x00 then 0x00, yes, I see that is true and not
what I
{Quote hidden}

and
> it should have been "stringstream".

Yes.  Me or Outlook.  Yeah I'll blame Outlook. <g>

>
> > // char I = 0 from your code?
> > Const char esc = 0x1B;
> > char i = 0;
> >
> > // A char goes through as 'binary' while an int is converted to
ASCII
> >
> > ss << "hello";        // Add hello as text
> > ss << i;                // Add I as a NULL single byte 0
>
> Oh? That works? Cool! Why does that work? If "i" had been 123 it would
> have
> appended 0x7B?

That is the stream part of stringstream.  It is a string builder that
works like an ostream.  Along the lines of how sprintf relates to
fprintf.


> > ss << (int)i;        // Add I as an ASCII string or 0x30
>
> And if "i" had been 123 then it would have appended 0x30,0x31,0x32?

Yes.

{Quote hidden}

allocate
> a
> char array on the heap, memcpy it and then return the char array, I
guess.

Do you have a function of some type that needs a char[]?  Can you just
save away the stringstream and later use the .str()?  

Could you save the string stream instead of an array of char?

Stringstream * func()
{
 stringstream * pSS = new stringstream();

 // Do your stuff
 *pss << "hello";

 return pss;
}

And return or save away the string stream instead of a char array.

{Quote hidden}

It is exactly the %c versus %d thing in a different set of functions.  A
char is by default treated as a %c type operation and an int like a %d
operation.

> So the << appends the binary value if the types match and
> the decimal value if they don't? That is NOWHERE in my documentation.
Time
> to start a web page...
>
> <snip>

Huge books are written on stl.

<sarcasm>
And Microsoft has always had documentation of the same quality as the
rest of their products -
</sarcasm>
So yeah if its in there is is darned hard to find.

> > > find a method that clears out a basic_stringstream to allow it to
be
{Quote hidden}

the
> objects to know what to do with themselves? Why isn't it ss.doneWith?
But
> that isn't a question for you, rather a question for whoever writes
the
> C++
> language.

I'm not real fond of what they did to C++ since the early versions.

The idea is that you create them when you need them and destroy them
when done.  The equivalent of malloc and free.   In C the style would be
to allocate a buffer use it, free it.  When you need to start over you
start with a fresh malloc.


> It's a strange world. But then I say that about Perl as well. And I'm
sure
> others feel the same about C or asm.

It's a mindset.  You get used to a tool by learning its idioms.
Although I have written object oriented assembly.  That was unusual to
many old assembly hacks.

>
> Thanks again.

You're welcome.  No problem.  Returning the favor of people helping me.




-------------------------------------  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
RemoveMEpostmasterEraseMEspamEraseMEvgt.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.

2006\02\28@105143 by William Killian

flavicon
face
> -----Original Message-----
> From: RemoveMEpiclist-bouncesspam_OUTspamKILLspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspamspammit.edu] On
Behalf
{Quote hidden}

can't
> point to one and read out bytes that contain what the string in basic
or
> the
> result of the pack function returns.

Actually they do.  That is what std::string::c_str() and
std::stringstream::str() do.  You read out the bytes contained by
calling those methods.

But in the OO world the implementation hiding is considered a good
thing.

You can get to individual elements of std::string easily with substr(),
insert characters in the middle with insert().

> You then have to convert them to such an array of characters by
calling
> their .str() function to make an actual string from the result.

That is reading out the bytes.  No 'conversion' per se, just limited
access to the char[] buffer inside.

> But, yes, it sounds like that is as close as it gets.

They are weird until you get used to them.  Now that I am I still think
I would have doen them differently (Bill's first law of software
engineering: All other programmers are idiots.  Tongue is extremely
firmly in cheek when I say that.)

Play with them and get used to them.  I/O formatting is weird but it
works.  Printf is still better in many cases though -  and probably more
efficient at a cost of making you do a lot of work and probably end up
with something not much more efficient at the end.


-------------------------------------  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
EraseMEpostmasterspamspamspamBeGonevgt.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.

2006\02\28@110359 by Alan B. Pearce

face picon face
>You get used to a tool by learning its idioms.
>Although I have written object oriented assembly.

Any pointers on where to get info on doing this? I tried to get the info
from Microsoft that was presented on this at last years Masters, without
success.

The nearest I have come to OOP in assembler is by using linkable modules.

2006\02\28@112924 by William Killian

flavicon
face


> -----Original Message-----
> From: RemoveMEpiclist-bouncesKILLspamspammit.edu [piclist-bouncesSTOPspamspamspam_OUTmit.edu] On
Behalf
> Of Alan B. Pearce
> Sent: Tuesday, February 28, 2006 11:04 AM
> To: Microcontroller discussion list - Public.
> Subject: Re: [EE] selecting the right C++ STD library memory buffer
>
> >You get used to a tool by learning its idioms.
> >Although I have written object oriented assembly.
>
> Any pointers on where to get info on doing this? I tried to get the
info
> from Microsoft that was presented on this at last years Masters,
without
> success.
>
> The nearest I have come to OOP in assembler is by using linkable
modules.

Hand rolled in 68k assembler.  I did all the class equivalent stuff
myself.  It was not the clean syntax of an object oriented language.  

OO is a mindset not a language.  Some languages just make it easier and
some (old BASIC for example) make it really really hard.




-------------------------------------  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
spamBeGonepostmasterSTOPspamspamEraseMEvgt.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.

2006\02\28@114440 by Alan B. Pearce

face picon face
>Hand rolled in 68k assembler.  I did all the
>class equivalent stuff myself.  It was not
>the clean syntax of an object oriented language.

OK, I just figured that maybe you had some specific methodology that helped.

>OO is a mindset not a language.

Yeah, appreciate that. I did find that using linkable modules (in this case
built through Olins environment) helped the OOP mindset with assembler as it
was possible to maintain a certain degree of "hidden detail" because of the
modules and the PIC banking (it was on a 16F876).

2006\02\28@190047 by Peter

picon face

On Tue, 28 Feb 2006, Alan B. Pearce wrote:

>> You get used to a tool by learning its idioms.
>> Although I have written object oriented assembly.
>
> Any pointers on where to get info on doing this? I tried to get the info
> from Microsoft that was presented on this at last years Masters, without
> success.
>
> The nearest I have come to OOP in assembler is by using linkable modules.

I think that you can use the usual 'system call interface' paradigm. All
data is private to a set of subroutines, which form an object. There is
a single entry point and you select the function (method) using a
parameter. Inheritance is by forwarding calls to an inherited object.

Peter


'[EE] selecting the right C++ STD library memory bu'
2006\03\01@101624 by William Killian
flavicon
face


> -----Original Message-----
> From: KILLspampiclist-bouncesspamBeGonespammit.edu [EraseMEpiclist-bouncesspamEraseMEmit.edu] On
Behalf
{Quote hidden}

info
> > from Microsoft that was presented on this at last years Masters,
without
> > success.
> >
> > The nearest I have come to OOP in assembler is by using linkable
> modules.
>
> I think that you can use the usual 'system call interface' paradigm.
All
> data is private to a set of subroutines, which form an object. There
is
> a single entry point and you select the function (method) using a
> parameter. Inheritance is by forwarding calls to an inherited object.
>
> Peter

What I've done in the past is use jump/call tables to simulate the
hidden vtable of C++.  Its not pure OOP so the academic programmers
freak out (same way they freak out when I call C++ Templates a Macro
facility).  You have to make your own 'this' with a parameter/register
pointing to a data 'structure'.  That is a lot like the
fputX/fprintX/sprintf type C functions where thepointer to FILE is the
equivalent of this really.  I use this approach in any language such as
C or assembler that doesn't directly support objects.  I try to make a
similar set of function/subroutines that use a similar API with
programming by difference.  I make generic routines for most integer
types for example with specialized ones called for some that are
effectively derived types.  None of this is new with C++ or even pure OO
languages from the '90s since all were inspired by Simula '67.

Even the new buzzwords of generic programming and design patterns are
really just old ideas we've been doing 'forever' just with fancy names.





-------------------------------------  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
@spam@postmaster@spam@spamspam_OUTvgt.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.

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...