What are 'aliased' stream buffers?
Asked Answered
C

3

3

What are 'aliased stream buffers`? I encountered the term in a comment on an answer of mine.

Cloudcapped answered 14/3, 2011 at 8:53 Comment(0)
B
3

I've never heard the term before, but in the thread you cite, the person who used it also gave an example: two streams which use the same streambuf.

Of course, just because two streams don't use the same streambuf, doesn't mean that data written to them doesn't ultimately end up in the same place; that they don't alias the same sink, if that is what is meant. There are filtering streambuf's, which forward the actual sinking and sourcing to another streambuf, and on most systems, it's possible to open a file at the system level, and connect a streambuf (or two) to it.

-- James Kanze

Banausic answered 14/3, 2011 at 9:5 Comment(1)
+1 for explaining my term :) I used the term aliasing because it is akin to the concept of pointer aliasingCackle
K
1

It means an object with different name, for example this:

ostream &lbw = cout;

lbw << "Shahid out" << "Sachin in" << endl; //goes to cout!
Kenay answered 14/3, 2011 at 9:1 Comment(6)
that's it? it's just a different name for a reference?Seemly
that makes stdout anti aliasedHydrated
@Naveen: Did I miss anything? Please correct me if I'm wrong. :-)Kenay
@Nawaz: I don't the answer, I was expecting bit more complicated than that :) I was suprised to see this.Seemly
@Naveen: Ohh... In C++, you can have a short alias of a very very long namespace, but when it comes to object, it's a reference which is sometimes called alias!Kenay
@Naveen, @Nawaz: I meant rdbuf sharing as aptly explained by others. References are just references. Pointers are just pointers. Pointers or reference are usually said to alias when they refer to (part of) the same memory location, within the same context that might make assumptions on identity and uniqueness of such references(otherwise, it is just another variable with the same value).Cackle
U
1

What probably was meant in the comment there is this:

ofstream file;
file.rdbuf(cout.rdbuf());

// writes to cout
file << "hello";

So now the check there doesn't work:

if(&file == &cout)
    // no, it doesn't
Ubald answered 14/3, 2011 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.