1. It is often simpler to implement stream buffers without buffering. If the corresponding streams
are not used frequently or are used only for output, buffering is probably not that important. (For
output, the difference between stream buffer iterators and pointers is not as bad as for input; the
main problem is comparing stream buffer iterators.) However, for stream buffers that are used
extensively, buffering should definitely be implemented.
2. The flag unitbuf causes output streams to flush the stream after each output operation. Correspondingly,
the manipulators flush and endl also flush the stream. For the best performance,
all three should probably be avoided. However, when writing to the console, for example, it is
probably still reasonable to flush the stream after writing complete lines. If you are stuck with a
program that makes heavy use of unitbuf, flush, or endl, you might consider using a special
stream buffer that does not use sync() to flush the stream buffer but uses another function that
is called when appropriate.
3. Tieing streams with the tie() function (see Section 15.12.1, page 819) also results in additional
flushing of streams. Thus, streams should be tied only if it is really necessary.
When implementing new stream buffers, it may be reasonable to implement them without buffering
first. Then, if the stream buffer is identified as a bottleneck, it is still possible to implement buffering
without affecting anything in the remainder of the application.
1 . มันมักจะง่ายกว่าการใช้บัฟเฟอร์กระแสโดยไม่ต้อง buffering . ถ้าไม่ได้ใช้บ่อย
กระแสที่สอดคล้องกันหรือจะใช้เฉพาะสำหรับ output buffering มันคงไม่สำคัญ (
ผลผลิต , ความแตกต่างระหว่างกระแสบัฟเฟอร์ iterators และตัวชี้เป็นไม่ดีเท่าที่ใส่ ;
ปัญหาหลักคือการเปรียบเทียบกระแสบัฟเฟอร์ iterators ) อย่างไรก็ตาม สำหรับกระแสบัฟเฟอร์ที่ใช้
อย่างกว้างขวาง buffering แน่นอนควรใช้ .
2 ธง unitbuf ทำให้เกิดกระแสออกล้างกระแสหลังการส่งออก ต้องกัน ,
manipulators และเปี่ยม Endl ยังล้างธาร เพื่อประสิทธิภาพที่ดีที่สุด ,
3 ควรหลีกเลี่ยง อย่างไรก็ตาม เมื่อเขียนไปยังคอนโซล , ตัวอย่างเช่น , มันเป็น
อาจจะยังเหมาะสมที่จะล้างกระแสหลังจากเขียนสายสมบูรณ์ ถ้าคุณจะติดอยู่กับ
โปรแกรมที่ทำให้การใช้งานหนักของ unitbuf ล้าง หรือ Endl คุณอาจพิจารณาการใช้พิเศษ
กระแสบัฟเฟอร์ที่ไม่ได้ใช้ sync() ล้างบัฟเฟอร์ แต่กระแสการใช้ฟังก์ชันอื่นที่เรียกว่าเมื่อเหมาะสม
.
3 กำลังกระแส ด้วยฟังก์ชัน ( ดูมาตรา 15.12.1 tie() ,หน้า 819 ) ยังมีผลในเพิ่มเติม
ด้วยกระแส ดังนั้น กระแสควรจะมัดไว้ ถ้ามันเป็น จำเป็นจริงๆ .
เมื่อใช้บัฟเฟอร์กระแสใหม่ มันอาจจะเหมาะสมที่จะใช้พวกเขาโดยไม่ต้อง buffering
ก่อน แล้วถ้ากระแสบัฟเฟอร์ถูกระบุเป็นคอขวด มันยังสามารถใช้บัฟเฟอร์
โดยไม่มีผลอะไรในส่วนที่เหลือของโปรแกรม
การแปล กรุณารอสักครู่..